Skip to content

Commit 88fcd0a

Browse files
committed
Framework build compatible with JDK 9 (tests running against java.base module)
Issue: SPR-13344
1 parent d07381e commit 88fcd0a

File tree

11 files changed

+211
-216
lines changed

11 files changed

+211
-216
lines changed

build.gradle

Lines changed: 171 additions & 138 deletions
Large diffs are not rendered by default.

spring-aop/src/test/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.
@@ -19,8 +19,8 @@
1919
import java.io.FileNotFoundException;
2020
import java.io.IOException;
2121
import java.lang.reflect.Method;
22+
import java.rmi.ConnectException;
2223
import java.rmi.RemoteException;
23-
import javax.transaction.TransactionRolledbackException;
2424

2525
import org.aopalliance.intercept.MethodInvocation;
2626
import org.junit.Test;
@@ -35,9 +35,9 @@
3535
* @author Rod Johnson
3636
* @author Chris Beams
3737
*/
38-
public final class ThrowsAdviceInterceptorTests {
38+
public class ThrowsAdviceInterceptorTests {
3939

40-
@Test(expected=IllegalArgumentException.class)
40+
@Test(expected = IllegalArgumentException.class)
4141
public void testNoHandlerMethods() {
4242
// should require one handler method at least
4343
new ThrowsAdviceInterceptor(new Object());
@@ -97,7 +97,7 @@ public void testCorrectHandlerUsedForSubclass() throws Throwable {
9797
MyThrowsHandler th = new MyThrowsHandler();
9898
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
9999
// Extends RemoteException
100-
TransactionRolledbackException ex = new TransactionRolledbackException();
100+
ConnectException ex = new ConnectException("");
101101
MethodInvocation mi = mock(MethodInvocation.class);
102102
given(mi.proceed()).willThrow(ex);
103103
try {
@@ -126,7 +126,7 @@ public void afterThrowing(RemoteException ex) throws Throwable {
126126

127127
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
128128
// Extends RemoteException
129-
TransactionRolledbackException ex = new TransactionRolledbackException();
129+
ConnectException ex = new ConnectException("");
130130
MethodInvocation mi = mock(MethodInvocation.class);
131131
given(mi.proceed()).willThrow(ex);
132132
try {

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.cache.jcache;
1818

19-
import javax.annotation.Resource;
2019
import javax.cache.CacheManager;
2120
import javax.cache.Caching;
2221
import javax.cache.configuration.MutableConfiguration;
@@ -26,6 +25,7 @@
2625
import org.junit.Ignore;
2726
import org.junit.Test;
2827

28+
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.cache.annotation.CachingConfigurerSupport;
3030
import org.springframework.cache.annotation.EnableCaching;
3131
import org.springframework.cache.config.AbstractCacheAnnotationTests;
@@ -81,7 +81,7 @@ public void testCustomCacheManager() {
8181
@EnableCaching
8282
static class EnableCachingConfig extends CachingConfigurerSupport {
8383

84-
@Resource
84+
@Autowired
8585
CachingProvider cachingProvider;
8686

8787
@Override

spring-context/src/main/java/org/springframework/ejb/access/AbstractRemoteSlsbInvokerInterceptor.java

Lines changed: 1 addition & 23 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.
@@ -22,7 +22,6 @@
2222
import javax.ejb.EJBHome;
2323
import javax.ejb.EJBObject;
2424
import javax.naming.NamingException;
25-
import javax.rmi.PortableRemoteObject;
2625

2726
import org.aopalliance.intercept.MethodInvocation;
2827

@@ -88,27 +87,6 @@ protected boolean isHomeRefreshable() {
8887
}
8988

9089

91-
/**
92-
* This overridden lookup implementation performs a narrow operation
93-
* after the JNDI lookup, provided that a home interface is specified.
94-
* @see #setHomeInterface
95-
* @see javax.rmi.PortableRemoteObject#narrow
96-
*/
97-
@Override
98-
protected Object lookup() throws NamingException {
99-
Object homeObject = super.lookup();
100-
if (this.homeInterface != null) {
101-
try {
102-
homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
103-
}
104-
catch (ClassCastException ex) {
105-
throw new RemoteLookupFailureException(
106-
"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
107-
}
108-
}
109-
return homeObject;
110-
}
111-
11290
/**
11391
* Check for EJB3-style home object that serves as EJB component directly.
11492
*/

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

Lines changed: 2 additions & 21 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.
@@ -29,10 +29,6 @@
2929
import org.aopalliance.intercept.MethodInvocation;
3030
import org.apache.commons.logging.Log;
3131
import org.apache.commons.logging.LogFactory;
32-
import org.omg.CORBA.COMM_FAILURE;
33-
import org.omg.CORBA.CompletionStatus;
34-
import org.omg.CORBA.NO_RESPONSE;
35-
import org.omg.CORBA.SystemException;
3632

3733
import org.springframework.remoting.RemoteAccessException;
3834
import org.springframework.remoting.RemoteConnectFailureException;
@@ -170,22 +166,7 @@ public static Exception convertRmiAccessException(
170166
public static boolean isConnectFailure(RemoteException ex) {
171167
return (ex instanceof ConnectException || ex instanceof ConnectIOException ||
172168
ex instanceof UnknownHostException || ex instanceof NoSuchObjectException ||
173-
ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException ||
174-
isCorbaConnectFailure(ex.getCause()));
175-
}
176-
177-
/**
178-
* Check whether the given RMI exception root cause indicates a CORBA
179-
* connection failure.
180-
* <p>This is relevant on the IBM JVM, in particular for WebSphere EJB clients.
181-
* <p>See the
182-
* <a href="http://www.redbooks.ibm.com/Redbooks.nsf/RedbookAbstracts/tips0243.html">IBM website</code>
183-
* for details.
184-
* @param ex the RMI exception to check
185-
*/
186-
private static boolean isCorbaConnectFailure(Throwable ex) {
187-
return ((ex instanceof COMM_FAILURE || ex instanceof NO_RESPONSE) &&
188-
((SystemException) ex).completed == CompletionStatus.COMPLETED_NO);
169+
ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException);
189170
}
190171

191172
}

spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public void singleResourceOnFileSystem() throws IOException {
7474

7575
@Test
7676
public void singleResourceInJar() throws IOException {
77-
Resource[] resources = resolver.getResources("java/net/URL.class");
77+
Resource[] resources = resolver.getResources("org/apache/commons/logging/Log.class");
7878
assertEquals(1, resources.length);
79-
assertProtocolAndFilenames(resources, "jar", "URL.class");
79+
assertProtocolAndFilenames(resources, "jar", "Log.class");
8080
}
8181

8282
@Ignore // passes under Eclipse, fails under Ant
@@ -145,16 +145,15 @@ private void assertProtocolAndFilenames(Resource[] resources, String protocol, S
145145
assertEquals("Correct number of files found", filenames.length, resources.length);
146146
for (Resource resource : resources) {
147147
String actualProtocol = resource.getURL().getProtocol();
148-
// resources from rt.jar get retrieved as jrt images on JDK 9, so let's simply accept that as a match too
149-
assertTrue(actualProtocol.equals(protocol) || ("jar".equals(protocol) && "jrt".equals(actualProtocol)));
148+
assertEquals(protocol, actualProtocol);
150149
assertFilenameIn(resource, filenames);
151150
}
152151
}
153152

154153
private void assertFilenameIn(Resource resource, String... filenames) {
155154
String filename = resource.getFilename();
156155
assertTrue(resource + " does not have a filename that matches any of the specified names",
157-
Arrays.stream(filenames).anyMatch(filename::endsWith));
156+
Arrays.stream(filenames).anyMatch(filename::endsWith));
158157
}
159158

160159
}

spring-core/src/test/java/org/springframework/util/Base64UtilsTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public void encodeToStringWithJdk8VsJaxb() throws UnsupportedEncodingException {
7474
assertEquals(Base64Utils.encodeToString(bytes), DatatypeConverter.printBase64Binary(bytes));
7575
assertArrayEquals(bytes, Base64Utils.decodeFromString(Base64Utils.encodeToString(bytes)));
7676
assertArrayEquals(bytes, DatatypeConverter.parseBase64Binary(DatatypeConverter.printBase64Binary(bytes)));
77-
7877
}
7978

8079
@Test

spring-oxm/oxm.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ configurations {
55
}
66
dependencies {
77
castor "org.codehaus.castor:castor-anttasks:1.4.1"
8-
castor "org.apache.velocity:velocity:1.7"
9-
xjc "com.sun.xml.bind:jaxb-xjc:2.1.17"
108
jibx "org.jibx:jibx-bind:1.2.6"
11-
jibx "bcel:bcel:5.1"
9+
xjc 'com.sun.xml.bind:jaxb-xjc:2.2.11'
10+
xjc 'javax.xml.bind:jaxb-api:2.2.11'
11+
xjc 'com.sun.xml.bind:jaxb-core:2.2.11'
12+
xjc 'com.sun.xml.bind:jaxb-impl:2.2.11'
13+
xjc 'javax.activation:activation:1.1.1'
1214
}
1315

1416
ext.genSourcesDir = "${buildDir}/generated-sources"

spring-oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,25 @@
2020
import java.util.Arrays;
2121
import java.util.HashMap;
2222
import java.util.Map;
23-
2423
import javax.xml.transform.sax.SAXResult;
2524
import javax.xml.transform.stream.StreamResult;
2625

26+
import org.castor.xml.XMLProperties;
2727
import org.custommonkey.xmlunit.NamespaceContext;
2828
import org.custommonkey.xmlunit.SimpleNamespaceContext;
2929
import org.custommonkey.xmlunit.XMLUnit;
3030
import org.custommonkey.xmlunit.XpathEngine;
31-
31+
import org.exolab.castor.xml.XercesXMLSerializerFactory;
3232
import org.junit.Test;
33-
3433
import org.mockito.InOrder;
35-
36-
import org.springframework.core.io.ClassPathResource;
37-
import org.springframework.oxm.AbstractMarshallerTests;
38-
3934
import org.w3c.dom.Document;
4035
import org.w3c.dom.NodeList;
41-
4236
import org.xml.sax.Attributes;
4337
import org.xml.sax.ContentHandler;
4438

39+
import org.springframework.core.io.ClassPathResource;
40+
import org.springframework.oxm.AbstractMarshallerTests;
41+
4542
import static org.custommonkey.xmlunit.XMLAssert.*;
4643
import static org.junit.Assert.assertEquals;
4744
import static org.junit.Assert.assertFalse;
@@ -117,6 +114,9 @@ protected CastorMarshaller createMarshaller() throws Exception {
117114
CastorMarshaller marshaller = new CastorMarshaller();
118115
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
119116
marshaller.setMappingLocation(mappingLocation);
117+
Map<String, String> props = new HashMap<>(1);
118+
props.put(XMLProperties.SERIALIZER_FACTORY, XercesXMLSerializerFactory.class.getName());
119+
marshaller.setCastorProperties(props);
120120
marshaller.afterPropertiesSet();
121121
return marshaller;
122122
}

spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 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.
@@ -18,8 +18,6 @@
1818

1919
import java.util.Map;
2020

21-
import javax.annotation.PostConstruct;
22-
2321
import org.junit.Test;
2422

2523
import org.springframework.aop.support.AopUtils;
@@ -153,10 +151,7 @@ static class EnableAspectJTxConfig {
153151
static class Spr11915Config {
154152

155153
@Autowired
156-
private ConfigurableApplicationContext applicationContext;
157-
158-
@PostConstruct
159-
public void initializeApp() {
154+
public void initializeApp(ConfigurableApplicationContext applicationContext) {
160155
applicationContext.getBeanFactory().registerSingleton(
161156
"qualifiedTransactionManager", new CallCountingTransactionManager());
162157
}

0 commit comments

Comments
 (0)