Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 191564 Details for
Bug 340482
[ClassUtil]: Proposal of a less intrusive Exception Handling
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
ClassUtil refactoring
class-util-patch.txt (text/plain), 4.69 KB, created by
Frank Appel
on 2011-03-19 04:40:03 EDT
(
hide
)
Description:
ClassUtil refactoring
Filename:
MIME Type:
Creator:
Frank Appel
Created:
2011-03-19 04:40:03 EDT
Size:
4.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.rwt >Index: src/org/eclipse/rwt/internal/util/ClassUtil.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt/org.eclipse.rap.rwt/src/org/eclipse/rwt/internal/util/ClassUtil.java,v >retrieving revision 1.1 >diff -u -r1.1 ClassUtil.java >--- src/org/eclipse/rwt/internal/util/ClassUtil.java 13 Mar 2011 15:20:44 -0000 1.1 >+++ src/org/eclipse/rwt/internal/util/ClassUtil.java 19 Mar 2011 08:14:12 -0000 >@@ -11,6 +11,7 @@ > package org.eclipse.rwt.internal.util; > > import java.lang.reflect.Constructor; >+import java.lang.reflect.InvocationTargetException; > > > public final class ClassUtil { >@@ -33,12 +34,18 @@ > > public static Object newInstance( Class type, Class[] paramTypes, Object[] paramValues ) { > ParamCheck.notNull( type, "type" ); >+ Object result = null; > try { >- return createInstance( type, paramTypes, paramValues ); >- } catch( Exception e ) { >- String msg = "Failed to create instance of type: " + type.getName(); >- throw new ClassInstantiationException( msg, e ); >+ result = createInstance( type, paramTypes, paramValues ); >+ } catch( RuntimeException rte ) { >+ throw rte; >+ } catch( InvocationTargetException ite ) { >+ rethrowRuntimeExceptions( ite ); >+ throwInstantiationException( type, ite.getCause() ); >+ } catch( Exception exception ) { >+ throwInstantiationException( type, exception ); > } >+ return result; > } > > private static Object createInstance( Class type, Class[] paramTypes, Object[] paramValues ) >@@ -51,7 +58,18 @@ > return constructor.newInstance( paramValues ); > } > >+ private static void rethrowRuntimeExceptions( InvocationTargetException ite ) { >+ if( ite.getCause() instanceof RuntimeException ) { >+ throw ( RuntimeException )ite.getCause(); >+ } >+ } >+ >+ private static void throwInstantiationException( Class type, Throwable cause ) { >+ String msg = "Failed to create instance of type: " + type.getName(); >+ throw new ClassInstantiationException( msg, cause ); >+ } >+ > private ClassUtil() { > // prevent instantiation > } >-} >+} >\ No newline at end of file >#P org.eclipse.rap.rwt.test >Index: src/org/eclipse/rwt/internal/util/ClassUtil_Test.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt.test/org.eclipse.rap.rwt.test/src/org/eclipse/rwt/internal/util/ClassUtil_Test.java,v >retrieving revision 1.1 >diff -u -r1.1 ClassUtil_Test.java >--- src/org/eclipse/rwt/internal/util/ClassUtil_Test.java 13 Mar 2011 15:20:41 -0000 1.1 >+++ src/org/eclipse/rwt/internal/util/ClassUtil_Test.java 19 Mar 2011 08:14:13 -0000 >@@ -10,7 +10,7 @@ > ******************************************************************************/ > package org.eclipse.rwt.internal.util; > >-import java.lang.reflect.InvocationTargetException; >+import java.io.IOException; > > import junit.framework.TestCase; > >@@ -31,6 +31,7 @@ > String stringParam; > Long longParam; > public PublicClass() { >+ this( null ); // avoid unused private constructor marker > } > private PublicClass( Object objectParam ) { > this.objectParam = objectParam; >@@ -46,11 +47,17 @@ > } > } > >- static class ClassWithExceptionInConstructor { >- ClassWithExceptionInConstructor() { >+ static class ClassWithRuntimeExceptionInConstructor { >+ ClassWithRuntimeExceptionInConstructor() { > throw new ConstructorException(); > } > } >+ >+ static class ClassWithCheckedExceptionInConstructor { >+ ClassWithCheckedExceptionInConstructor() throws IOException { >+ throw new IOException(); >+ } >+ } > > public void testNewInstanceWithNullClass() { > try { >@@ -86,12 +93,20 @@ > assertEquals( instance.getClass(), PublicClass.class ); > } > >- public void testNewInstanceWithEceptionInConstructor() { >+ public void testNewInstanceWithRuntimeExceptionInConstructor() { > try { >- ClassUtil.newInstance( ClassWithExceptionInConstructor.class ); >+ ClassUtil.newInstance( ClassWithRuntimeExceptionInConstructor.class ); > fail(); >- } catch( ClassInstantiationException e ) { >- assertEquals( e.getCause().getClass(), InvocationTargetException.class ); >+ } catch( ConstructorException expected ) { >+ } >+ } >+ >+ public void testNewInstanceWithCheckedExceptionInConstructor() { >+ try { >+ ClassUtil.newInstance( ClassWithCheckedExceptionInConstructor.class ); >+ fail(); >+ } catch( ClassInstantiationException expected ) { >+ assertEquals( expected.getCause().getClass(), IOException.class ); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 340482
: 191564