Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem running schemagen with JDK 1.8 when createJavaDocAnnotations is true #40

Closed
netzling opened this issue Dec 8, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@netzling
Copy link

netzling commented Dec 8, 2015

When running schemagen from the command line (the 1.8 version) everything is fine, a schema is generated as expected. When the jaxb2-maven-plugin runs schemagen, it fails with a report that says that schemagen did not finish properly. Running maven with the -e flag I get the following cause:

Caused by: java.lang.IllegalArgumentException: Not supported: indent-number
    at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:571)
    at org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.getFactory(XsdGeneratorHelper.java:544)
    at org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.getHumanReadableXml(XsdGeneratorHelper.java:440)
    at org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.savePrettyPrintedDocument(XsdGeneratorHelper.java:508)
    at org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.insertJavaDocAsAnnotations(XsdGeneratorHelper.java:233)
    at org.codehaus.mojo.jaxb2.schemageneration.AbstractXsdGeneratorMojo.performExecution(AbstractXsdGeneratorMojo.java:454)
    ... 22 more

POM sets java to 1.8:

                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.3</version>
                            <configuration>
                                    <source>1.8</source>
                                    <target>1.8</target>
                            </configuration>
                    </plugin>

The plugin is run like so:

                    <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>jaxb2-maven-plugin</artifactId>
                            <version>2.2</version>
                            <configuration>
                                    <sources>
                                            <source>src/main/java/testdata</source>
                                    </sources>
                            </configuration>
                            <executions>
                                    <execution>
                                            <id>schemagen</id>
                                            <goals>
                                                    <goal>schemagen</goal>
                                            </goals>
                                    </execution>
                            </executions>
                            <!-- Use default configuration, implying that sources are read from the 
                                    directory src/main/java below the project basedir. (i.e. getProject().getCompileSourceRoots() 
                                    in Maven-speak). -->
                    </plugin>                       

Output with mvn -X -e compile:

Apache Maven 3.0.5 (Red Hat 3.0.5-16)
Maven home: /usr/share/maven
Java version: 1.8.0_65, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-2.b17.el7_1.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.20.1.el7.x86_64", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml

...

Will attach the complete log.

@netzling
Copy link
Author

netzling commented Dec 8, 2015

Complete log for running maven with mvn -X -e compile: log.txt

@netzling
Copy link
Author

netzling commented Dec 8, 2015

It appears that indent-number is only accepted by Xalan in JDK 1.7 and 1.6, see http://stackoverflow.com/questions/15134861/java-lang-illegalargumentexception-not-supported-indent-number.

@netzling
Copy link
Author

netzling commented Dec 8, 2015

Setting the configuration property createJavaDocAnnotations to false avoids the problem, but is, of course, only a workaround.

@netzling netzling changed the title Problem running schemagen with JDK 1.8 Problem running schemagen with JDK 1.8 when createJavaDocAnnotations is true Dec 8, 2015
@lennartj lennartj self-assigned this Dec 14, 2015
@lennartj lennartj added the bug label Dec 14, 2015
@lennartj
Copy link
Member

I suppose we can handle this in the plugin by checking the JDK version, and applying the correct setting.
If possible, we would need the same functionality to create human-readable comments (i.e. with indentation) even under JDK 8.

@cyberoblivion
Copy link

This issue also appears if you have transformSchemas, even if you turn off createJavaDocAnnotations, you will get this exception until you remove all transformSchemas.

@lennartj
Copy link
Member

The error is thrown from the following code snippet:

    private static TransformerFactory getFactory() {

        if (FACTORY == null) {

            try {
                FACTORY = TransformerFactory.newInstance();

                // Harmonize XML formatting
                FACTORY.setAttribute("indent-number", 2);

            } catch (Throwable exception) {

                // This should really not happen... but it seems to happen in some test cases.
                throw new IllegalStateException("Could not acquire TransformerFactory implementation.", exception);
            }
        }

        // All done.
        return FACTORY;
    }

... where the desired outcome is to provide a more sensible XSD formatting than if the indent-number argument was not provided. The "indent-number" parameter, in turn is found - along with the other accepted parameters - in the implementation of the TransformerFactory. The implementation found within the JDK8 (com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl) does contain the constant - so I believe that you are using a TransformerFactory other than the JDK8 internal one.

However, a simple way to handle IllegalArgumentException is simply to catch it and move on. In case the TransformerFactory implementation does not support the indent-number attribute, the user will simply get a less well-formatted, generated XSD as a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants