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

Remove usage of javax.xml.bind.DatatypeConverter (removed in Java 9) #5027

Closed
osiegmar opened this issue Aug 30, 2017 · 5 comments
Closed

Remove usage of javax.xml.bind.DatatypeConverter (removed in Java 9) #5027

osiegmar opened this issue Aug 30, 2017 · 5 comments

Comments

@osiegmar
Copy link
Contributor

osiegmar commented Aug 30, 2017

Since #3093 Checkstyle uses javax.xml.bind.DatatypeConverter to create a hex string of an SHA1 hash.

JDK 9 marks the package (module) javax.xml.bind as deprecated for removal - javadoc. Whole list of deprecations - here .

More dramatically, the current use in Checkstyle results in a NoClassDefFoundError/ClassNotFoundException if java weren't started with the --add-modules javax.xml.bind parameter.

java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
        at com.puppycrawl.tools.checkstyle.PropertyCacheFile.getHashCodeBasedOnObjectContent(PropertyCacheFile.java:233)
        at com.puppycrawl.tools.checkstyle.PropertyCacheFile.load(PropertyCacheFile.java:118)
        at com.puppycrawl.tools.checkstyle.Checker.setCacheFile(Checker.java:151)
@romani
Copy link
Member

romani commented Aug 30, 2017

-all jar do work on jdk9:

$ cat MyClass.java 
public class MyClass {
    public int[] getBar() {
        return new int[]
                         { 0, 1,
                           2, 3
                         };
    }
}

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="cacheFile" value="cachefile"/>
    <module name="SuppressWarningsFilter"/>
    <module name="TreeWalker">
        <module name="ArrayTrailingComma">
        </module>
    </module>
</module>

$ JAVA_HOME="/opt/jvm/jdk-9_181/" PATH=$JAVA_HOME/bin:$PATH java --version ; java -jar checkstyle-8.1-all.jar -c config.xml MyClass.java
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Starting audit...
[ERROR] /var/tmp/MyClass.java:6: Array should contain trailing comma. [ArrayTrailingComma]
Audit done.
Checkstyle ends with 1 errors.

$ cat cachefile 
#Wed Aug 30 07:09:57 PDT 2017
configuration*?=18A8818945B160C34EC0362E89145AB72F42B633

but there is error during compilation when target is 1.9 java with disabled maven-enforcer-plugin:

$ JAVA_HOME="/opt/jvm/jdk-9_181/" PATH=$JAVA_HOME/bin:$PATH mvn compile
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules...
[INFO] Installing Nexus Staging features:
[INFO]   ... total of 1 executions of maven-deploy-plugin replaced with nexus-staging-maven-plugin
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building checkstyle 8.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.2:enforce (enforce-maven) @ checkstyle ---
[INFO] 
[INFO] --- antlr-maven-plugin:2.2:generate (default) @ checkstyle ---
[INFO] grammar [java.g] was up-to-date; skipping
[INFO] 
[INFO] --- antlr4-maven-plugin:4.7:antlr4 (default) @ checkstyle ---
[INFO] No grammars to process
[INFO] ANTLR 4: Processing source directory /home/rivanov/java/github/checkstyle/checkstyle/src/main/resources
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (add-source) @ checkstyle ---
[INFO] Source directory: /home/rivanov/java/github/checkstyle/checkstyle/target/generated-sources/antlr added.
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ checkstyle ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 163 resources
[INFO] Copying 1 resource
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-test-source) @ checkstyle ---
[INFO] Test Source directory: /home/rivanov/java/github/checkstyle/checkstyle/src/test/resources added.
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-it-test-source) @ checkstyle ---
[INFO] Test Source directory: /home/rivanov/java/github/checkstyle/checkstyle/src/it/java added.
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (add-it-test-resource) @ checkstyle ---
[INFO] Test Source directory: /home/rivanov/java/github/checkstyle/checkstyle/src/it/resources added.
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.2:compile (default-compile) @ checkstyle ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 356 source files to /home/rivanov/java/github/checkstyle/checkstyle/target/classes
[INFO] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java: Some input files use or override a deprecated API.
[INFO] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/gui/TreeTable.java: Recompile with -Xlint:deprecation for details.
[INFO] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/api/AutomaticBean.java: Some input files use unchecked or unsafe operations.
[INFO] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/api/AutomaticBean.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java:[42,17] package javax.xml.bind is not visible
  (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.865 s
[INFO] Finished at: 2017-08-30T06:58:36-07:00
[INFO] Final Memory: 27M/91M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.2:compile (default-compile) on project checkstyle: Compilation failure
[ERROR] /home/rivanov/java/github/checkstyle/checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java:[42,17] package javax.xml.bind is not visible
[ERROR] (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

@romani
Copy link
Member

romani commented Aug 30, 2017

@osiegmar ,

the current use in Checkstyle results in a

can you share how you use Checkstyle ? to know where such problem could happen.
I can not reproduce problems with our CLI, see my post above.

@osiegmar
Copy link
Contributor Author

It doesn't work here. I have created the exact same MyClass.java and config.xml. My java --version says:

java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

Also note, that I'm on macOS.

java -jar checkstyle-8.1-all.jar -c config.xml MyClass.java gives:

com.puppycrawl.tools.checkstyle.api.CheckstyleException: Cannot set property 'cacheFile' to 'cachefile' in module Checker
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:212)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:164)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:504)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:431)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:209)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2127)
	at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2108)
	at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:437)
	at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:202)
	... 4 more
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
	at com.puppycrawl.tools.checkstyle.PropertyCacheFile.getHashCodeBasedOnObjectContent(PropertyCacheFile.java:233)
	at com.puppycrawl.tools.checkstyle.PropertyCacheFile.load(PropertyCacheFile.java:118)
	at com.puppycrawl.tools.checkstyle.Checker.setCacheFile(Checker.java:151)
	... 12 more
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	... 15 more

@osiegmar
Copy link
Contributor Author

@romani romani added this to the 8.2 milestone Aug 30, 2017
@romani
Copy link
Member

romani commented Aug 30, 2017

fix is merged, I hope it will work for all.

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

No branches or pull requests

2 participants