src/share/jaxws_classes/com/sun/xml/internal/bind/v2/ClassFactory.java

Print this page




 103 
 104             if(!Modifier.isPublic(classMod) || !Modifier.isPublic(cons.getModifiers())) {
 105                 // attempt to make it work even if the constructor is not accessible
 106                 try {
 107                     cons.setAccessible(true);
 108                 } catch(SecurityException e) {
 109                     // but if we don't have a permission to do so, work gracefully.
 110                     logger.log(Level.FINE,"Unable to make the constructor of "+clazz+" accessible",e);
 111                     throw e;
 112                 }
 113             }
 114 
 115             m.put(clazz,new WeakReference<Constructor>(cons));
 116         }
 117 
 118         return cons.newInstance(emptyObject);
 119     }
 120 
 121     /**
 122      * The same as {@link #create0} but with an error handling to make
 123      * the instanciation error fatal.
 124      */
 125     public static <T> T create( Class<T> clazz ) {
 126         try {
 127             return create0(clazz);
 128         } catch (InstantiationException e) {
 129             logger.log(Level.INFO,"failed to create a new instance of "+clazz,e);
 130             throw new InstantiationError(e.toString());
 131         } catch (IllegalAccessException e) {
 132             logger.log(Level.INFO,"failed to create a new instance of "+clazz,e);
 133             throw new IllegalAccessError(e.toString());
 134         } catch (InvocationTargetException e) {
 135             Throwable target = e.getTargetException();
 136 
 137             // most likely an error on the user's code.
 138             // just let it through for the ease of debugging
 139             if(target instanceof RuntimeException)
 140                 throw (RuntimeException)target;
 141 
 142             // error. just forward it for the ease of debugging
 143             if(target instanceof Error)




 103 
 104             if(!Modifier.isPublic(classMod) || !Modifier.isPublic(cons.getModifiers())) {
 105                 // attempt to make it work even if the constructor is not accessible
 106                 try {
 107                     cons.setAccessible(true);
 108                 } catch(SecurityException e) {
 109                     // but if we don't have a permission to do so, work gracefully.
 110                     logger.log(Level.FINE,"Unable to make the constructor of "+clazz+" accessible",e);
 111                     throw e;
 112                 }
 113             }
 114 
 115             m.put(clazz,new WeakReference<Constructor>(cons));
 116         }
 117 
 118         return cons.newInstance(emptyObject);
 119     }
 120 
 121     /**
 122      * The same as {@link #create0} but with an error handling to make
 123      * the instantiation error fatal.
 124      */
 125     public static <T> T create( Class<T> clazz ) {
 126         try {
 127             return create0(clazz);
 128         } catch (InstantiationException e) {
 129             logger.log(Level.INFO,"failed to create a new instance of "+clazz,e);
 130             throw new InstantiationError(e.toString());
 131         } catch (IllegalAccessException e) {
 132             logger.log(Level.INFO,"failed to create a new instance of "+clazz,e);
 133             throw new IllegalAccessError(e.toString());
 134         } catch (InvocationTargetException e) {
 135             Throwable target = e.getTargetException();
 136 
 137             // most likely an error on the user's code.
 138             // just let it through for the ease of debugging
 139             if(target instanceof RuntimeException)
 140                 throw (RuntimeException)target;
 141 
 142             // error. just forward it for the ease of debugging
 143             if(target instanceof Error)