JDK-6203483 : apt fails to catch errors thrown by a ClassLoader when loading a factory
  • Type: Bug
  • Component: tools
  • Sub-Component: apt
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-12-02
  • Updated: 2010-04-02
  • Resolved: 2005-02-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u4Fixed 6 b25Fixed
Description
The following results in a uncaught error from apt:

mkdir foo
touch foo/bar.class
apt -factory foo/bar

An exception has occurred in apt (1.5.0_01). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.NoClassDefFoundError: IllegalName: foo/bar
        at java.lang.ClassLoader.preDefineClass(ClassLoader.java:476)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:614)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at com.sun.tools.apt.comp.Apt.main(Apt.java:287)
        at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:458)
        at com.sun.tools.apt.main.Main.compile(Main.java:1075)
        at com.sun.tools.apt.main.Main.compile(Main.java:938)
        at com.sun.tools.apt.Main.processing(Main.java:95)
        at com.sun.tools.apt.Main.process(Main.java:43)
        at com.sun.tools.apt.Main.main(Main.java:34)

The cause is the catch blocks for 

AnnotationProcessorFactory factory = 
			    (AnnotationProcessorFactory) (aptCL.loadClass(factoryName).newInstance());
			list.add(factory);

do not check for the NoClassDefFoundError that can be thrown by the classloader.



Comments
SUGGESTED FIX src/share/classes/com/sun/tools/apt/comp>sccs sccsdiff -r1.17 -r1.18 Apt.java ------- Apt.java ------- 272c272 < * Otherwise, if the "-factory" option is used, seach --- > * Otherwise, if the "-factory" option is used, search 295a296,297 > } catch(Throwable t) { > throw new AnnotationProcessingError(t); 296a299 > 414a418,419 > } catch(Throwable t) { > throw new AnnotationProcessingError(t); 416d420 < ###@###.### 2005-2-08 01:24:31 GMT
08-02-2005

EVALUATION Appropriate catch blocks should be added. ###@###.### 2005-1-13 21:57:24 GMT
13-01-2005