Skip to content

Commit 75fc0f8

Browse files
committed
Framework build compatible with JDK 9 (even with -target 1.9)
Issue: SPR-13344
1 parent 9f2cb3e commit 75fc0f8

File tree

3 files changed

+20
-82
lines changed

3 files changed

+20
-82
lines changed

build.gradle

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ configure(allprojects) { project ->
3232
version = qualifyVersionIfNecessary(version)
3333

3434
ext.activationApiVersion = "1.1.1"
35+
ext.annotationApiVersion = "1.2"
3536
ext.aspectjVersion = "1.9.0.BETA-4"
3637
ext.beanvalVersion = "1.1.0.Final"
3738
ext.caffeineVersion = "2.3.1"
@@ -55,6 +56,7 @@ configure(allprojects) { project ->
5556
ext.jackson2Version = "2.8.1"
5657
ext.javamailVersion = "1.5.5"
5758
ext.jaxbVersion = "2.2.11"
59+
ext.jaxwsVersion = "2.2.11"
5860
ext.jcaVersion = "1.7"
5961
ext.jettyVersion = "9.3.10.v20160621"
6062
ext.jodaVersion = "2.9.4"
@@ -489,6 +491,8 @@ project("spring-context") {
489491
compile(files(project(":spring-core").cglibRepackJar))
490492
optional(project(":spring-instrument"))
491493
optional("javax.inject:javax.inject:1")
494+
optional("javax.annotation:javax.annotation-api:${annotationApiVersion}")
495+
optional("javax.xml.ws:jaxws-api:${jaxwsVersion}")
492496
optional("javax.ejb:javax.ejb-api:${ejbApiVersion}")
493497
optional("javax.interceptor:javax.interceptor-api:${interceptorApiVersion}")
494498
optional("javax.enterprise.concurrent:javax.enterprise.concurrent-api:1.0")
@@ -517,6 +521,8 @@ project("spring-oxm") {
517521
dependencies {
518522
compile(project(":spring-beans"))
519523
compile(project(":spring-core"))
524+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
525+
optional("javax.activation:activation:${activationApiVersion}")
520526
optional("org.codehaus.castor:castor-xml:1.4.1") {
521527
exclude group: 'stax', module: 'stax-api'
522528
exclude group: "org.springframework", module: "spring-context"
@@ -535,10 +541,8 @@ project("spring-oxm") {
535541
testCompile(files(genCastor.classesDir).builtBy(genCastor))
536542
testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
537543
testRuntime("xerces:xercesImpl:2.11.0") // for Castor
538-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
539544
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
540545
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
541-
testRuntime("javax.activation:activation:${activationApiVersion}")
542546
}
543547
}
544548

@@ -562,6 +566,7 @@ project("spring-messaging") {
562566
}
563567
optional("org.eclipse.jetty.websocket:websocket-client:${jettyVersion}")
564568
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
569+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
565570
testCompile("javax.inject:javax.inject-tck:1")
566571
testCompile("javax.servlet:javax.servlet-api:${servletVersion}")
567572
testCompile("javax.validation:validation-api:${beanvalVersion}")
@@ -579,7 +584,6 @@ project("spring-messaging") {
579584
testCompile("io.netty:netty-all:${nettyVersion}")
580585
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
581586
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
582-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
583587
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
584588
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
585589
testRuntime("javax.activation:activation:${activationApiVersion}")
@@ -650,6 +654,7 @@ project("spring-context-support") {
650654
compile(project(":spring-context"))
651655
optional(project(":spring-jdbc")) // for Quartz support
652656
optional(project(":spring-tx")) // for Quartz support
657+
optional("javax.activation:activation:${activationApiVersion}")
653658
optional("javax.mail:javax.mail-api:${javamailVersion}")
654659
optional("javax.cache:cache-api:1.0.0")
655660
optional("com.github.ben-manes.caffeine:caffeine:${caffeineVersion}")
@@ -697,6 +702,7 @@ project("spring-web") {
697702
optional("javax.el:javax.el-api:${elApiVersion}")
698703
optional("javax.faces:javax.faces-api:2.2")
699704
optional("javax.validation:validation-api:${beanvalVersion}")
705+
optional("javax.activation:activation:${activationApiVersion}")
700706
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
701707
optional("com.caucho:hessian:4.0.38")
702708
optional("commons-fileupload:commons-fileupload:${fileuploadVersion}")
@@ -731,6 +737,8 @@ project("spring-web") {
731737
optional("com.google.protobuf:protobuf-java:${protobufVersion}")
732738
optional("com.google.protobuf:protobuf-java-util:${protobufVersion}")
733739
optional("com.googlecode.protobuf-java-format:protobuf-java-format:1.4")
740+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
741+
optional("javax.xml.ws:jaxws-api:${jaxwsVersion}")
734742
optional("javax.mail:javax.mail-api:${javamailVersion}")
735743
testCompile(project(":spring-context-support")) // for JafMediaTypeFactory
736744
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
@@ -747,11 +755,8 @@ project("spring-web") {
747755
testCompile("org.eclipse.jetty:jetty-server:${jettyVersion}")
748756
testCompile("org.eclipse.jetty:jetty-servlet:${jettyVersion}")
749757
testCompile("com.squareup.okhttp3:mockwebserver:3.0.1")
750-
testRuntime("javax.xml.ws:jaxws-api:2.2.11")
751-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
752758
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
753759
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
754-
testRuntime("javax.activation:activation:${activationApiVersion}")
755760
}
756761
}
757762

@@ -765,6 +770,7 @@ project("spring-web-reactive") {
765770
compile "io.projectreactor:reactor-core:${reactorCoreVersion}"
766771
optional(project(":spring-context-support")) // for FreeMarker support
767772
provided "javax.servlet:javax.servlet-api:${servletVersion}"
773+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
768774
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
769775
optional("org.freemarker:freemarker:${freemarkerVersion}")
770776
optional "org.apache.httpcomponents:httpclient:4.5.1" // Needed to run Javadoc without error
@@ -782,7 +788,6 @@ project("spring-web-reactive") {
782788
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
783789
testCompile("javax.validation:validation-api:${beanvalVersion}")
784790
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
785-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
786791
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
787792
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
788793
testRuntime("javax.activation:activation:${activationApiVersion}")
@@ -830,6 +835,7 @@ project("spring-webmvc") {
830835
optional(project(":spring-oxm")) // for MarshallingView
831836
optional("javax.servlet.jsp:javax.servlet.jsp-api:${jspVersion}")
832837
optional("javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1")
838+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
833839
optional("org.apache.poi:poi:${poiVersion}")
834840
optional("org.apache.poi:poi-ooxml:${poiVersion}")
835841
optional("org.freemarker:freemarker:${freemarkerVersion}")
@@ -883,7 +889,6 @@ project("spring-webmvc") {
883889
testRuntime("org.jruby:jruby:9.1.2.0")
884890
testRuntime("org.python:jython-standalone:2.5.3")
885891
testRuntime("org.webjars:underscorejs:1.8.3")
886-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
887892
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
888893
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
889894
testRuntime("javax.activation:activation:${activationApiVersion}")
@@ -965,6 +970,8 @@ project("spring-test") {
965970
}
966971
optional("javax.el:javax.el-api:${elApiVersion}")
967972
optional("javax.websocket:javax.websocket-api:${websocketVersion}")
973+
optional("javax.activation:activation:${activationApiVersion}")
974+
optional("javax.xml.bind:jaxb-api:${jaxbVersion}")
968975
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
969976
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
970977
optional("org.hamcrest:hamcrest-core:${hamcrestVersion}")
@@ -1004,10 +1011,8 @@ project("spring-test") {
10041011
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
10051012
testRuntime("org.ehcache:ehcache:${ehcache3Version}")
10061013
testRuntime("org.terracotta:management-model:2.0.0")
1007-
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
10081014
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
10091015
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
1010-
testRuntime("javax.activation:activation:${activationApiVersion}")
10111016
}
10121017

10131018
task testNG(type: Test) {

spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiClientInterceptor.java

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,28 +21,23 @@
2121
import java.rmi.RemoteException;
2222
import javax.naming.Context;
2323
import javax.naming.NamingException;
24-
import javax.rmi.PortableRemoteObject;
2524

2625
import org.aopalliance.intercept.MethodInterceptor;
2726
import org.aopalliance.intercept.MethodInvocation;
28-
import org.omg.CORBA.OBJECT_NOT_EXIST;
29-
import org.omg.CORBA.SystemException;
3027

3128
import org.springframework.aop.support.AopUtils;
3229
import org.springframework.beans.factory.InitializingBean;
3330
import org.springframework.jndi.JndiObjectLocator;
34-
import org.springframework.remoting.RemoteAccessException;
3531
import org.springframework.remoting.RemoteConnectFailureException;
3632
import org.springframework.remoting.RemoteInvocationFailureException;
3733
import org.springframework.remoting.RemoteLookupFailureException;
3834
import org.springframework.remoting.support.DefaultRemoteInvocationFactory;
3935
import org.springframework.remoting.support.RemoteInvocation;
4036
import org.springframework.remoting.support.RemoteInvocationFactory;
41-
import org.springframework.util.ReflectionUtils;
4237

4338
/**
44-
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services from JNDI.
45-
* Typically used for RMI-IIOP (CORBA), but can also be used for EJB home objects
39+
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services
40+
* from JNDI. Typically used for RMI-IIOP but can also be used for EJB home objects
4641
* (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup,
4742
* this accessor also performs narrowing through PortableRemoteObject.
4843
*
@@ -74,7 +69,6 @@
7469
* @see org.springframework.remoting.RemoteAccessException
7570
* @see java.rmi.RemoteException
7671
* @see java.rmi.Remote
77-
* @see javax.rmi.PortableRemoteObject#narrow
7872
*/
7973
public class JndiRmiClientInterceptor extends JndiObjectLocator implements MethodInterceptor, InitializingBean {
8074

@@ -227,17 +221,7 @@ else if (getServiceInterface() != null) {
227221
*/
228222
protected Object lookupStub() throws RemoteLookupFailureException {
229223
try {
230-
Object stub = lookup();
231-
if (getServiceInterface() != null && !(stub instanceof RmiInvocationHandler)) {
232-
try {
233-
stub = PortableRemoteObject.narrow(stub, getServiceInterface());
234-
}
235-
catch (ClassCastException ex) {
236-
throw new RemoteLookupFailureException(
237-
"Could not narrow RMI stub to service interface [" + getServiceInterface().getName() + "]", ex);
238-
}
239-
}
240-
return stub;
224+
return lookup();
241225
}
242226
catch (NamingException ex) {
243227
throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex);
@@ -306,14 +290,6 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
306290
throw ex;
307291
}
308292
}
309-
catch (SystemException ex) {
310-
if (isConnectFailure(ex)) {
311-
return handleRemoteConnectFailure(invocation, ex);
312-
}
313-
else {
314-
throw ex;
315-
}
316-
}
317293
finally {
318294
getJndiTemplate().releaseContext(ctx);
319295
}
@@ -330,17 +306,6 @@ protected boolean isConnectFailure(RemoteException ex) {
330306
return RmiClientInterceptorUtils.isConnectFailure(ex);
331307
}
332308

333-
/**
334-
* Determine whether the given CORBA exception indicates a connect failure.
335-
* <p>The default implementation checks for CORBA's
336-
* {@link org.omg.CORBA.OBJECT_NOT_EXIST} exception.
337-
* @param ex the RMI exception to check
338-
* @return whether the exception should be treated as connect failure
339-
*/
340-
protected boolean isConnectFailure(SystemException ex) {
341-
return (ex instanceof OBJECT_NOT_EXIST);
342-
}
343-
344309
/**
345310
* Refresh the stub and retry the remote invocation if necessary.
346311
* <p>If not configured to refresh on connect failure, this method
@@ -402,9 +367,6 @@ protected Object doInvoke(MethodInvocation invocation, Object stub) throws Throw
402367
catch (RemoteException ex) {
403368
throw convertRmiAccessException(ex, invocation.getMethod());
404369
}
405-
catch (SystemException ex) {
406-
throw convertCorbaAccessException(ex, invocation.getMethod());
407-
}
408370
catch (InvocationTargetException ex) {
409371
throw ex.getTargetException();
410372
}
@@ -423,9 +385,6 @@ protected Object doInvoke(MethodInvocation invocation, Object stub) throws Throw
423385
if (targetEx instanceof RemoteException) {
424386
throw convertRmiAccessException((RemoteException) targetEx, invocation.getMethod());
425387
}
426-
else if (targetEx instanceof SystemException) {
427-
throw convertCorbaAccessException((SystemException) targetEx, invocation.getMethod());
428-
}
429388
else {
430389
throw targetEx;
431390
}
@@ -483,27 +442,4 @@ private Exception convertRmiAccessException(RemoteException ex, Method method) {
483442
return RmiClientInterceptorUtils.convertRmiAccessException(method, ex, isConnectFailure(ex), getJndiName());
484443
}
485444

486-
/**
487-
* Convert the given CORBA SystemException that happened during remote access
488-
* to Spring's RemoteAccessException if the method signature does not declare
489-
* RemoteException. Else, return the SystemException wrapped in a RemoteException.
490-
* @param method the invoked method
491-
* @param ex the RemoteException that happened
492-
* @return the exception to be thrown to the caller
493-
*/
494-
private Exception convertCorbaAccessException(SystemException ex, Method method) {
495-
if (ReflectionUtils.declaresException(method, RemoteException.class)) {
496-
// A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions.
497-
return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex);
498-
}
499-
else {
500-
if (isConnectFailure(ex)) {
501-
return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex);
502-
}
503-
else {
504-
return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", ex);
505-
}
506-
}
507-
}
508-
509445
}

spring-context/src/main/java/org/springframework/remoting/rmi/JndiRmiServiceExporter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.rmi.RemoteException;
2222
import java.util.Properties;
2323
import javax.naming.NamingException;
24-
import javax.rmi.PortableRemoteObject;
2524

2625
import org.springframework.beans.factory.DisposableBean;
2726
import org.springframework.beans.factory.InitializingBean;
@@ -117,7 +116,6 @@ public void prepare() throws NamingException, RemoteException {
117116

118117
// Initialize and cache exported object.
119118
this.exportedObject = getObjectToExport();
120-
PortableRemoteObject.exportObject(this.exportedObject);
121119

122120
rebind();
123121
}
@@ -143,7 +141,6 @@ public void destroy() throws NamingException, NoSuchObjectException {
143141
logger.info("Unbinding RMI service from JNDI location [" + this.jndiName + "]");
144142
}
145143
this.jndiTemplate.unbind(this.jndiName);
146-
PortableRemoteObject.unexportObject(this.exportedObject);
147144
}
148145

149146
}

0 commit comments

Comments
 (0)