Browse Source

Consistent deprecation markers on JDK 9

pull/1296/head
Juergen Hoeller 9 years ago
parent
commit
1cb381e9a7
  1. 2
      spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java
  2. 7
      spring-core/src/test/java/org/springframework/util/xml/AbstractStaxHandlerTestCase.java
  3. 9
      spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java
  4. 25
      spring-core/src/test/java/org/springframework/util/xml/DomContentHandlerTests.java
  5. 11
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  6. 1
      spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java
  7. 9
      spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java

2
spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

@ -3543,6 +3543,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
} }
@SuppressWarnings("serial")
public static class CustomHashMap<K, V> extends LinkedHashMap<K, V> implements CustomMap<K, V> { public static class CustomHashMap<K, V> extends LinkedHashMap<K, V> implements CustomMap<K, V> {
} }
@ -3551,6 +3552,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
} }
@SuppressWarnings("serial")
public static class CustomHashSet<E> extends LinkedHashSet<E> implements CustomSet<E> { public static class CustomHashSet<E> extends LinkedHashSet<E> implements CustomSet<E> {
} }

7
spring-core/src/test/java/org/springframework/util/xml/AbstractStaxHandlerTestCase.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xmlunit.util.Predicate; import org.xmlunit.util.Predicate;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -59,12 +58,14 @@ public abstract class AbstractStaxHandlerTestCase {
private static final Predicate<Node> nodeFilter = (n -> n.getNodeType() != Node.COMMENT_NODE && private static final Predicate<Node> nodeFilter = (n -> n.getNodeType() != Node.COMMENT_NODE &&
n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE); n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE);
private XMLReader xmlReader; private XMLReader xmlReader;
@Before @Before
@SuppressWarnings("deprecation") // on JDK 9
public void createXMLReader() throws Exception { public void createXMLReader() throws Exception {
xmlReader = XMLReaderFactory.createXMLReader(); xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
} }

9
spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTestCase.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,6 @@ import org.xml.sax.Locator;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler; import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -47,6 +46,9 @@ import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*; import static org.mockito.BDDMockito.*;
/**
* @author Arjen Poutsma
*/
public abstract class AbstractStaxXMLReaderTestCase { public abstract class AbstractStaxXMLReaderTestCase {
protected static XMLInputFactory inputFactory; protected static XMLInputFactory inputFactory;
@ -57,9 +59,10 @@ public abstract class AbstractStaxXMLReaderTestCase {
@Before @Before
@SuppressWarnings("deprecation") // on JDK 9
public void setUp() throws Exception { public void setUp() throws Exception {
inputFactory = XMLInputFactory.newInstance(); inputFactory = XMLInputFactory.newInstance();
standardReader = XMLReaderFactory.createXMLReader(); standardReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
standardContentHandler = mockContentHandler(); standardContentHandler = mockContentHandler();
standardReader.setContentHandler(standardContentHandler); standardReader.setContentHandler(standardContentHandler);
} }

25
spring-core/src/test/java/org/springframework/util/xml/DomContentHandlerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,21 +16,19 @@
package org.springframework.util.xml; package org.springframework.util.xml;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import static org.junit.Assert.assertThat;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/** /**
* Unit tests for {@link DomContentHandler}. * Unit tests for {@link DomContentHandler}.
@ -49,6 +47,7 @@ public class DomContentHandlerTests {
private static final String XML_2_SNIPPET = private static final String XML_2_SNIPPET =
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />"; "<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
private Document expected; private Document expected;
private DomContentHandler handler; private DomContentHandler handler;
@ -59,15 +58,18 @@ public class DomContentHandlerTests {
private DocumentBuilder documentBuilder; private DocumentBuilder documentBuilder;
@Before @Before
@SuppressWarnings("deprecation") // on JDK 9
public void setUp() throws Exception { public void setUp() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder(); documentBuilder = documentBuilderFactory.newDocumentBuilder();
result = documentBuilder.newDocument(); result = documentBuilder.newDocument();
xmlReader = XMLReaderFactory.createXMLReader(); xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
} }
@Test @Test
public void contentHandlerDocumentNamespacePrefixes() throws Exception { public void contentHandlerDocumentNamespacePrefixes() throws Exception {
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
@ -96,7 +98,6 @@ public class DomContentHandlerTests {
xmlReader.setContentHandler(handler); xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
assertThat("Invalid result", result, isSimilarTo(expected)); assertThat("Invalid result", result, isSimilarTo(expected));
} }
} }

11
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

@ -100,8 +100,7 @@ import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils; import org.springframework.util.xml.StaxUtils;
/** /**
* Implementation of the {@code GenericMarshaller} interface for JAXB 2.1/2.2, * Implementation of the {@code GenericMarshaller} interface for JAXB 2.2.
* as included in JDK 6 update 4+ and Java 7/8.
* *
* <p>The typical usage will be to set either the "contextPath" or the "classesToBeBound" * <p>The typical usage will be to set either the "contextPath" or the "classesToBeBound"
* property on this bean, possibly customize the marshaller and unmarshaller by setting * property on this bean, possibly customize the marshaller and unmarshaller by setting
@ -544,6 +543,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
} }
} }
@SuppressWarnings("deprecation") // on JDK 9
private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException { private Schema loadSchema(Resource[] resources, String schemaLanguage) throws IOException, SAXException {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Setting validation schema to " + logger.debug("Setting validation schema to " +
@ -588,7 +588,6 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
supportsInternal(classArgument, false)); supportsInternal(classArgument, false));
} }
else if (typeArgument instanceof GenericArrayType) { else if (typeArgument instanceof GenericArrayType) {
// Only on JDK 6 - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041784
GenericArrayType arrayType = (GenericArrayType) typeArgument; GenericArrayType arrayType = (GenericArrayType) typeArgument;
return (Byte.TYPE == arrayType.getGenericComponentType()); return (Byte.TYPE == arrayType.getGenericComponentType());
} }
@ -773,9 +772,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
} }
catch (NullPointerException ex) { catch (NullPointerException ex) {
if (!isSupportDtd()) { if (!isSupportDtd()) {
throw new UnmarshallingFailureException("NPE while unmarshalling. " + throw new UnmarshallingFailureException("NPE while unmarshalling: " +
"This can happen on JDK 1.6 due to the presence of DTD " + "This can happen due to the presence of DTD declarations which are disabled.", ex);
"declarations, which are disabled.", ex);
} }
throw ex; throw ex;
} }
@ -804,6 +802,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
} }
} }
@SuppressWarnings("deprecation") // on JDK 9
private Source processSource(Source source) { private Source processSource(Source source) {
if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) { if (StaxUtils.isStaxSource(source) || source instanceof DOMSource) {
return source; return source;

1
spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

@ -183,6 +183,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
* @return the XMLReader * @return the XMLReader
* @throws SAXException if thrown by JAXP methods * @throws SAXException if thrown by JAXP methods
*/ */
@SuppressWarnings("deprecation") // on JDK 9
protected XMLReader createXmlReader() throws SAXException { protected XMLReader createXmlReader() throws SAXException {
XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); XMLReader xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd()); xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !isSupportDtd());

9
spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -171,6 +171,7 @@ public class DataAccessUtilsTests {
} }
@Test @Test
@SuppressWarnings("deprecation") // on JDK 9
public void withEquivalentIntegerInstanceTwice() { public void withEquivalentIntegerInstanceTwice() {
Collection<Integer> col = new ArrayList<>(2); Collection<Integer> col = new ArrayList<>(2);
col.add(new Integer(5)); col.add(new Integer(5));
@ -273,10 +274,8 @@ public class DataAccessUtilsTests {
public static class MapPersistenceExceptionTranslator implements PersistenceExceptionTranslator { public static class MapPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
/** // in to out
* in to out private final Map<RuntimeException, RuntimeException> translations = new HashMap<>();
*/
private Map<RuntimeException,RuntimeException> translations = new HashMap<>();
public void addTranslation(RuntimeException in, RuntimeException out) { public void addTranslation(RuntimeException in, RuntimeException out) {
this.translations.put(in, out); this.translations.put(in, out);

Loading…
Cancel
Save