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

com.sun.xml.ws.model.Injector incompatible with Java 11 #55

Closed
bkabelka opened this issue Apr 18, 2019 · 3 comments · Fixed by #251
Closed

com.sun.xml.ws.model.Injector incompatible with Java 11 #55

bkabelka opened this issue Apr 18, 2019 · 3 comments · Fixed by #251

Comments

@bkabelka
Copy link

With OpenJDK 11.0.2 and JAX-WS 2.3.2, calling javax.xml.ws.Service.getPort(QName, Class<T>) (e.g. from a service implementation) leads to a java.lang.NoSuchMethodException (after fixing issue #54 by the workaround mentioned there). This exception is thrown in com.sun.xml.ws.model.Injector, as the method sun.misc.Unsafe.defineClass(...) no longer exists in Java 11 after being deprecated in Java 9 (see also https://bugs.openjdk.java.net/browse/JDK-8193033):

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(Native Method)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.Injector.<clinit>(Injector.java:75)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.WrapperBeanGenerator.createRequestWrapperBean(WrapperBeanGenerator.java:265)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.RuntimeModeler.getRequestWrapperClass(RuntimeModeler.java:345)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:771)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:701)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:461)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:290)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:70)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:44)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:28)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:90)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:852)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:869)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:832)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:421)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:390)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:372)
	at java.xml.ws/javax.xml.ws.Service.getPort(Service.java:139)
	[...]
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:2109)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.Injector$3.run(Injector.java:79)
	at com.sun.xml.ws.jaxws/com.sun.xml.ws.model.Injector$3.run(Injector.java:75)
	... 60 more

A possible workaround is to start your application with the --add-opens java.base/java.lang=com.sun.xml.ws.jaxws flag. In this case, the defineClass(...) method of java.lang.ClassLoader is used instead than the one from sun.misc.Unsafe.

However, I would expect the JAX-WS library to work without any additional --add-opens statements.

@smillidge
Copy link
Contributor

Can you create a PR for this as it looks like you understand the fix?

@bkabelka
Copy link
Author

Well, I am afraid that is not that easy. Opening java.lang to com.sun.xml.ws.jaxws would only be possible in java.base. Replacing the method sun.misc.Unsafe.defineClass(...) with another alternative is not that straight-forward either, from what I've read: While there is a replacement method, classes can no longer be injected into packages that did not intend to give such access. As I have no idea how this Injector is actually used, I am not able to provide a usable PR here.

@vogella
Copy link

vogella commented May 7, 2021

Stopped working with Java 16 / 17, see #225

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

Successfully merging a pull request may close this issue.

3 participants