question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java 16: java.security.PrivilegedActionException: java.lang.NoSuchMethodException:

See original GitHub issue
SEVERE: null
java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:558)
	at com.sun.xml.bind.v2.runtime.reflect.opt.Injector.<clinit>(Injector.java:197)
	at com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:81)
	at com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:125)
	at com.sun.xml.bind.v2.runtime.reflect.Accessor$GetterSetterReflection.optimize(Accessor.java:402)
	at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:92)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at com.sun.xml.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:128)
	at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:181)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:514)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:331)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:139)
	at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1156)
	at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:165)
	at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:289)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:217)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:175)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:353)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:508)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:465)
	at org.jvnet.jaxb2_commons.plugin.inheritance.Customizations.<clinit>(Customizations.java:28)
	at org.jvnet.jaxb2_commons.plugin.inheritance.InheritancePlugin.getCustomizationElementNames(InheritancePlugin.java:49)
	at org.jvnet.jaxb2_commons.plugin.AbstractPlugin.getCustomizationURIs(AbstractPlugin.java:97)
	at com.sun.tools.xjc.reader.AbstractExtensionBindingChecker.<init>(AbstractExtensionBindingChecker.java:101)
	at com.sun.tools.xjc.reader.ExtensionBindingChecker.<init>(ExtensionBindingChecker.java:81)
	at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:246)
	at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:381)
	at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
	at com.sun.xml.xsom.impl.parser.ParserContext.<init>(ParserContext.java:104)
	at com.sun.xml.xsom.parser.XSOMParser.<init>(XSOMParser.java:113)
	at com.sun.tools.xjc.ModelLoader.createXSOMParser(ModelLoader.java:419)
	at com.sun.tools.xjc.ModelLoader.createXSOMParser(ModelLoader.java:427)
	at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:509)
	at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:360)
	at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:162)
	at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:117)
	at org.jvnet.mjiip.v_2_3.XJC23Mojo.loadModel(XJC23Mojo.java:50)
	at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute(XJC23Mojo.java:40)
	at org.jvnet.mjiip.v_2_3.XJC23Mojo.doExecute(XJC23Mojo.java:28)
	at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:478)
	at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:320)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
	at java.base/java.lang.Class.getMethod(Class.java:2195)
	at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:201)
	at com.sun.xml.bind.v2.runtime.reflect.opt.Injector$3.run(Injector.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
	... 71 more

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

18reactions
kliakoscommented, Mar 26, 2021

I still experience issues with this and I’ve narrowed it down to the existence of a bindings file. If I remove the .xjb file then it works properly. However, when the .xjb file is present, the build fails with the java.security.PrivilegedActionException.

I still need the binding to convert XMLGregorianCalendar into a better type so prefer not to remove it. Does anyone have similar problem? Or a suggestion on how to solve it?

Try overriding the jaxb-runtime dependency inside maven-jaxb2-plugin.

	<build>
		<plugins>
			<plugin>
				<groupId>org.jvnet.jaxb2.maven2</groupId>
				<artifactId>maven-jaxb2-plugin</artifactId>
				<version>0.14.0</version>
				<dependencies>
					<dependency>
						<groupId>org.glassfish.jaxb</groupId>
						<artifactId>jaxb-runtime</artifactId>
						<version>2.3.3</version>
					</dependency>
				</dependencies>
				<executions>
                                ...
10reactions
kliakoscommented, Mar 19, 2021

Overriding jaxb-runtime to anything >= 2.3.1 fixes this. (https://github.com/highsource/maven-jaxb2-plugin/issues/148)

Read more comments on GitHub >

github_iconTop Results From Across the Web

sun.misc.Unsafe.defineClass(java.lang.String,[B,int ...
I had a similar error message when migrating my projects and libraries from java 16 to java 17. I was using the -illegal-access=permit ......
Read more >
PrivilegedActionException (Java Platform SE 7 )
The "exception thrown by the privileged computation" that is provided at construction time and accessed via the getException() method is now known as...
Read more >
Schemas' cannot build with JDK-16 (or 17-ea) - ASF JIRA
Schema creation accesses 'sun.misc.Unsafe#defineClass', which is no longer available java.security.PrivilegedActionException: java.lang.
Read more >
Why am I getting a NoSuchMethodException when using ...
NoSuchMethodException : MyCustomClass.method(java.lang. ... We have checked the java connector and class but it appears to contain the proper method ...
Read more >
15 openjdk 16 Cannot invoke "java.lang.reflect.Method. ...
Injector <clinit> SCHWERWIEGEND: null java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found