CNFE for loading class using classLoader from JCommander due to wrong META-INF/MANIFEST.MF
dipak-pawar opened this issue · comments
Jcommander Version
1.72
Description:
- Run
jar -xvf jcommander-1.73.jar
- Check for
META-INF/MANIFEST.MF
content - This causes problem to load any class from jcommander using
this.getClass().getClassLoader().loadClass(ParameterException.class.getName());
Reproducer Project
https://github.com/dipak-pawar/jcommander-classloading/tree/jcommander_classloader
Expected output
Class should load fine.
Actual Content - META-INF/MANIFEST.MF
Manifest-Version: 1.0
Bundle-Description: A Java library to parse command line options
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
Export-Package: com.beust.jcommander.converters;version="1.73",com.beu
st.jcommander.defaultprovider;version="1.73",com.beust.jcommander;ver
sion="1.73",com.beust.jcommander.internal;version="1.73",com.beust.jc
ommander.validators;version="1.73"
Build-Date: 2018-02-23
Bundle-SymbolicName: jcommander
Bundle-Version: 1.73
Bundle-Name: com.beust.jcommander
Bundle-ManifestVersion: 2
Bnd-LastModified: 1519401535143
Created-By: 1.8.0_121 (Oracle Corporation)
Tool: Bnd-3.5.0.201709291849
Manifest-Version: 1.0
Bundle-Description: A Java library to parse command line options
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
Export-Package: com.beust.jcommander.converters;version="1.73",com.beu
st.jcommander.defaultprovider;version="1.73",com.beust.jcommander;ver
sion="1.73",com.beust.jcommander.internal;version="1.73",com.beust.jc
ommander.validators;version="1.73"
Build-Date: 2018-02-23
Bundle-SymbolicName: jcommander
Bundle-Version: 1.73
Bundle-Name: com.beust.jcommander
Bundle-ManifestVersion: 2
Bnd-LastModified: 1519401551333
Created-By: 1.8.0_121 (Oracle Corporation)
Tool: Bnd-3.5.0.201709291849
Expected Content - META-INF/MANIFEST.MF
Manifest-Version: 1.0
Bundle-Description: A Java library to parse command line options
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
Export-Package: com.beust.jcommander.converters;version="1.73",com.beu
st.jcommander.defaultprovider;version="1.73",com.beust.jcommander;ver
sion="1.73",com.beust.jcommander.internal;version="1.73",com.beust.jc
ommander.validators;version="1.73"
Build-Date: 2018-02-23
Bundle-SymbolicName: jcommander
Bundle-Version: 1.73
Bundle-Name: com.beust.jcommander
Bundle-ManifestVersion: 2
Bnd-LastModified: 1519401535143
Created-By: 1.8.0_121 (Oracle Corporation)
Tool: Bnd-3.5.0.201709291849
This also causes TestNG 6.14.3 to fail on Gradle:
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 5.
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:95)
at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:88)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
... 25 more
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader$1.run(URLClassLoader.java:370)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 28 more
Caused by: java.io.IOException: invalid manifest format
at java.util.jar.Manifest.read(Manifest.java:225)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:194)
at java.util.jar.JarFile.getManifest(JarFile.java:180)
at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:981)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:450)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
... 34 more
As said in #435, I got that error too and fixing the duplicate entries works.
The two tickets relate but there are different problems (missing header, ...).
@cbeust Any updates on this?
Should be fixed in 1.74.
@cbeust Unfortunately, this seems to have reappeared for release 1.75:
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.JCommander
at java.net.URLClassLoader$1.run(URLClassLoader.java:370)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 54 more
Caused by: java.io.IOException: invalid manifest format
at java.util.jar.Manifest.read(Manifest.java:225)
at java.util.jar.Manifest.<init>(Manifest.java:69)
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:194)
at java.util.jar.JarFile.getManifest(JarFile.java:180)
at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:981)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:450)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
... 60 more
Also mentioned here: 85cb6f7#commitcomment-32810824
@cbeust any change of rolling a 1.76 release with this fixed?
I wonder what's triggering the duplicate content?
Any updates on resolving this at all?
Fixed in 1.78.