JDK-8073519 : schemagen does not report errors while generating xsd files
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxb
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-02-20
  • Updated: 2016-08-24
  • Resolved: 2015-10-16
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.
JDK 8 JDK 9
8u72Fixed 9 b88Fixed
Description
Created a test-class which has syntax error, and provided as input to schemagen for xsd generation. The schemagen doesnt report any errors and simply exits.

import javax.xml.bind.annotation.XmlType;

@XmlType
public class TestClassType {
     public int a;
     compile-error;
}

command: schemagen TestClassType.java

When the input file has no errors the schema file gets generated.
Comments
JDK7 prints the messages to stderr stream and to fix this regression fix should be slightly modified to print to the stderr directly instead of class Logger usage: + for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) { + System.err.println(d.toString()); + } With this modifications output is the same as generated by JDK7: TestWrongType.java:6: error: ';' expected int compile-error; ^ TestWrongType.java:6: error: <identifier> expected int compile-error; ^
02-10-2015

With proposed changes schemagen generates the following output: Sep 30, 2015 9:32:29 PM com.sun.tools.internal.jxc.SchemaGenerator$Runner compile SEVERE: TestWrongType.java:6: error: <identifier> expected compile-error; ^ Sep 30, 2015 9:32:29 PM com.sun.tools.internal.jxc.SchemaGenerator$Runner compile SEVERE: TestWrongType.java:6: error: <identifier> expected compile-error;
30-09-2015

The issue is applicable to JDK8 and 9 only.
30-09-2015

The issue was introduced by standalone project changes and then it was synced to JDK8 source. The SchemaGenerator class was changed to use javax.tools.JavaCompiler (instead of com.sun.tools.apt.process), but the diagnostic information generated by javac is silently ignored. The following patch solves the reported problem: diff -r 51729143f8fe src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java --- a/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java Sat Sep 26 09:22:24 2015 -0700 +++ b/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/SchemaGenerator.java Wed Sep 30 21:21:57 2015 +0300 @@ -30,6 +30,7 @@ import com.sun.xml.internal.bind.util.Which; import javax.lang.model.SourceVersion; +import javax.tools.Diagnostic; import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; @@ -248,7 +249,12 @@ if (episode != null) r.setEpisodeFile(episode); task.setProcessors(Collections.singleton(r)); - return task.call(); + boolean res = task.call(); + for( Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics() ) { + Level l = (d.getKind() == Diagnostic.Kind.ERROR) ? Level.SEVERE : Level.WARNING; + LOGGER.log(l, d.toString()); + } + return res; } }
30-09-2015

Is the issue applicable to JDK 9?
23-07-2015