JDK-8134326 : Invoking com.sun.tools.internal.jxc.SchemaGenerator through reflection with -XaddExports causes runtime error
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxb
  • Affected Version: 9-repo-jigsaw
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-08-24
  • Updated: 2016-01-06
  • Resolved: 2015-10-09
Related Reports
Relates :  
Description
com.sun.tools.internal.jxc.SchemaGenerator is invoked through reflection with following option specified:

-XaddExports:jdk.xml.bind/com.sun.tools.internal.jxc=ALL-UNNAMED

on JDK jigsaw build this leads to following error:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base@9.0/Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(java.base@9.0/NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9.0/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@9.0/Method.java:502)
        at com.sun.tools.internal.jxc.SchemaGenerator.run(jdk.xml.bind@9.0/SchemaGenerator.java:151)
        at com.sun.tools.internal.jxc.SchemaGenerator.run(jdk.xml.bind@9.0/SchemaGenerator.java:76)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base@9.0/Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(java.base@9.0/NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9.0/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@9.0/Method.java:502)
        at Test1.generate(Test1.java:21)
        at Test1.main(Test1.java:28)
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol (in module: jdk.compiler) cannot be cast to java.lang.Class (in module: java.base)
        at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(jdk.compiler@9.0/JavacTaskImpl.java:144)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(jdk.compiler@9.0/JavacTaskImpl.java:93)
        at com.sun.tools.javac.api.JavacTaskImpl.call(jdk.compiler@9.0/JavacTaskImpl.java:87)
        at com.sun.tools.internal.jxc.SchemaGenerator$Runner.compile(jdk.xml.bind@9.0/SchemaGenerator.java:251)
        ... 12 more
Caused by: java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol (in module: jdk.compiler) cannot be cast to java.lang.Class (in module: java.base)
        at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.collectGetterSetters(java.xml.bind@9.0/ClassInfoImpl.java:1011)
        at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.findGetterSetterProperties(java.xml.bind@9.0/ClassInfoImpl.java:932)
        at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.getProperties(java.xml.bind@9.0/ClassInfoImpl.java:299)
        at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(java.xml.bind@9.0/ModelBuilder.java:246)
        at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getClassInfo(java.xml.bind@9.0/ModelBuilder.java:212)
        at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(java.xml.bind@9.0/ModelBuilder.java:360)
        at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.getTypeInfo(java.xml.bind@9.0/ModelBuilder.java:375)
        at com.sun.tools.internal.jxc.api.impl.j2s.JavaCompilerImpl.bind(jdk.xml.bind@9.0/JavaCompilerImpl.java:80)
        at com.sun.tools.internal.jxc.ap.SchemaGenerator.process(jdk.xml.bind@9.0/SchemaGenerator.java:95)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(jdk.compiler@9.0/JavacProcessingEnvironment.java:862)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(jdk.compiler@9.0/JavacProcessingEnvironment.java:774)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2100(jdk.compiler@9.0/JavacProcessingEnvironment.java:103)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(jdk.compiler@9.0/JavacProcessingEnvironment.java:1085)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(jdk.compiler@9.0/JavacProcessingEnvironment.java:1193)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(jdk.compiler@9.0/JavaCompiler.java:1243)
        at com.sun.tools.javac.main.JavaCompiler.compile(jdk.compiler@9.0/JavaCompiler.java:921)
        at com.sun.tools.javac.api.JavacTaskImpl$1.call(jdk.compiler@9.0/JavacTaskImpl.java:97)
        at com.sun.tools.javac.api.JavacTaskImpl$1.call(jdk.compiler@9.0/JavacTaskImpl.java:93)
        at com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(jdk.compiler@9.0/JavacTaskImpl.java:128)
        ... 15 more

The minimized testcase is attached. Following step should be undertaken in order to reproduce this bug:

1. Unzip attached archive minimized.zip to some Windows host.
2. Modify run.bat by setting JDK_HOME to the latest jigsaw JDK installation directory.
3. Run run.bat.
Comments
ClassCastException looks like coming from the following code casts "c" to java.lang.Class private void collectGetterSetters(C c, Map<String,M> getters, Map<String,M> setters) { Modules.ensureReadable(ClassInfoImpl.class, (Class) c);
29-09-2015

JDK-8134418 is another bug tracking the same failure mode.
03-09-2015