Skip to content
Permalink
Browse files
Start cleaning up some usage of deprecated API's now that we are Java11
  • Loading branch information
dkulp committed Apr 13, 2022
1 parent ea0212e commit cad4f0b76bb79f82a5ef4bc7e435e93996eb884b
Showing 89 changed files with 145 additions and 129 deletions.
@@ -76,8 +76,8 @@ class TunedDocumentLoader extends DefaultDocumentLoader {
try {
Class<?> cls = ClassLoaderUtils.loadClass("com.ctc.wstx.sax.WstxSAXParserFactory",
TunedDocumentLoader.class);
saxParserFactory = (SAXParserFactory)cls.newInstance();
nsasaxParserFactory = (SAXParserFactory)cls.newInstance();
saxParserFactory = (SAXParserFactory)cls.getDeclaredConstructor().newInstance();
nsasaxParserFactory = (SAXParserFactory)cls.getDeclaredConstructor().newInstance();
} catch (Throwable e) {
//woodstox not found, use any other Stax parser
saxParserFactory = SAXParserFactory.newInstance();
@@ -257,7 +257,7 @@ public Label createLabel() {
cwClass);
@SuppressWarnings("unused")
Label l = new Label() {
Object l = cls.newInstance();
Object l = cls.getDeclaredConstructor().newInstance();
public Object getValue() {
return l;
}
@@ -359,7 +359,7 @@ private static char[] getKeyPassword(KeyManagersType kmc) {
}
try {
final CallbackHandler ch = (CallbackHandler) ClassLoaderUtils
.loadClass(callbackHandlerClass, TLSParameterJaxBUtils.class).newInstance();
.loadClass(callbackHandlerClass, TLSParameterJaxBUtils.class).getDeclaredConstructor().newInstance();
String prompt = kmc.getKeyStore().getFile();
if (prompt == null) {
prompt = kmc.getKeyStore().getResource();
@@ -97,7 +97,8 @@ private String[] getAnnotationObjectNames(Annotation ann) {

private <T> T initializeAnnotationObject(String annObjectName, Class<T> type) {
try {
final Object object = ClassLoaderUtils.loadClass(annObjectName, this.getClass()).newInstance();
final Object object = ClassLoaderUtils.loadClass(annObjectName, this.getClass())
.getDeclaredConstructor().newInstance();
return type.cast(object);
} catch (Throwable e) {
throw new Fault(new org.apache.cxf.common.i18n.Message(
@@ -107,7 +108,7 @@ private <T> T initializeAnnotationObject(String annObjectName, Class<T> type) {
}
private <T> T initializeAnnotationObject(Class<T> type) {
try {
return type.cast(type.newInstance());
return type.cast(type.getDeclaredConstructor().newInstance());
} catch (Throwable e) {
throw new Fault(new org.apache.cxf.common.i18n.Message(
"COULD_NOT_CREATE_ANNOTATION_OBJECT",
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -181,9 +182,10 @@ public static XMLInputFactory getXMLInputFactory(Message m) {
}

try {
xif = (XMLInputFactory)(cls.newInstance());
xif = (XMLInputFactory)(cls.getDeclaredConstructor().newInstance());
factories.put(o, xif);
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new Fault(e);
}
}
@@ -21,6 +21,7 @@

import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -183,9 +184,10 @@ public static XMLOutputFactory getXMLOutputFactory(Message m) {
}

try {
xif = (XMLOutputFactory)(cls.newInstance());
xif = (XMLOutputFactory)(cls.getDeclaredConstructor().newInstance());
factories.put(o, xif);
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new Fault(e);
}
}
@@ -52,7 +52,7 @@ public Object create(Exchange ex) throws Throwable {
if (Modifier.isAbstract(svcClass.getModifiers())) {
throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
}
Object o = svcClass.newInstance();
Object o = svcClass.getDeclaredConstructor().newInstance();
Bus b = ex.getBus();
ResourceManager resourceManager = b.getExtension(ResourceManager.class);
if (resourceManager != null) {
@@ -189,7 +189,8 @@ private XMLValidationSchema getValidator(Endpoint endpoint, ServiceInfo serviceI
try {
// I don't think that we need the baseURI.
Method method = multiSchemaFactory.getMethod("createSchema", String.class, Map.class);
ret = (XMLValidationSchema) method.invoke(multiSchemaFactory.newInstance(), null, sources);
ret = (XMLValidationSchema) method.invoke(multiSchemaFactory.getDeclaredConstructor().newInstance(),
null, sources);
endpoint.put(KEY, ret);
} catch (Throwable t) {
LOG.log(Level.INFO, "Problem loading schemas. Falling back to slower method.", ret);
@@ -175,11 +175,11 @@ private void tryToParseSchemas() throws Exception {
//bug in the JDK doesn't set this, but accesses it
config.setParameter("http://www.oracle.com/xml/jaxp/properties/xmlSecurityPropertyManager",
Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager")
.newInstance());
.getDeclaredConstructor().newInstance());

config.setParameter("http://apache.org/xml/properties/security-manager",
Class.forName("com.sun.org.apache.xerces.internal.utils.XMLSecurityManager")
.newInstance());
.getDeclaredConstructor().newInstance());
} catch (Throwable t) {
//ignore
}
@@ -34,7 +34,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThrows;

public class MicrometerMetricsAutoConfigurationTest {
@@ -27,7 +27,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class BraveTracerContextTest {
private Tracing brave;
@@ -26,7 +26,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class OpenTracingContextTest {
private OpenTracingContext context;
@@ -32,6 +32,7 @@
import com.sun.javadoc.RootDoc;
import com.sun.javadoc.Tag;


public final class DumpJavaDoc {

private DumpJavaDoc() {
@@ -38,7 +38,7 @@

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemPackages;
@@ -252,7 +252,7 @@ protected void setUserException(CorbaMessage message,
// one has not been created on the servant side which throws the UserException.
if (fault == null) {
Class<?> faultClass = faultMethod.getReturnType();
fault = faultClass.newInstance();
fault = faultClass.getDeclaredConstructor().newInstance();
}

CorbaFaultStreamWriter faultWriter = new CorbaFaultStreamWriter(orb, exType,
@@ -95,7 +95,7 @@ public void testWriteChar() {
OutputStream oStream = orb.create_output_stream();

CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
Character charValue = new Character('c');
Character charValue = Character.valueOf('c');
writer.writeChar(charValue);

InputStream iStream = oStream.create_input_stream();
@@ -108,7 +108,7 @@ public void testWriteWChar() {
OutputStream oStream = orb.create_output_stream();

CorbaObjectWriter writer = new CorbaObjectWriter(oStream);
Character wcharValue = new Character('w');
Character wcharValue = Character.valueOf('w');
writer.writeChar(wcharValue);

InputStream iStream = oStream.create_input_stream();
@@ -78,7 +78,7 @@ public void testCreateCorbaBoolean() {

@Test
public void testCreateCorbaChararacter() {
Character val = new Character('c');
Character val = Character.valueOf('c');
CorbaPrimitiveHandler obj =
new CorbaPrimitiveHandler(new QName("char"),
CorbaConstants.NT_CORBA_CHAR,
@@ -106,7 +106,7 @@ public void testCreateCorbaChararacter() {

@Test
public void testCreateCorbaWChararacter() {
Character val = new Character('w');
Character val = Character.valueOf('w');
CorbaPrimitiveHandler obj =
new CorbaPrimitiveHandler(new QName("wchar"),
CorbaConstants.NT_CORBA_WCHAR,
@@ -282,7 +282,7 @@ public void testCreateCorbaULongLong() {

@Test
public void testCreateCorbaFloat() {
Float val = new Float(1234.56);
Float val = Float.valueOf(1234.56f);
CorbaPrimitiveHandler obj =
new CorbaPrimitiveHandler(new QName("float"),
CorbaConstants.NT_CORBA_FLOAT,
@@ -19,6 +19,8 @@

package org.apache.cxf.binding.soap.saaj;

import java.lang.reflect.InvocationTargetException;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
@@ -95,16 +97,10 @@ private static <T> T newInstanceCxfSAAJFactory(String factoryName, Class<T> cls)
throws SOAPException {
try {
Class<?> klass = Class.forName(factoryName);
return cls.cast(klass.newInstance());
} catch (ClassNotFoundException cnfe) {
throw new SOAPException("Provider " + factoryName + " could not be instantiated: "
+ cnfe, cnfe);
} catch (InstantiationException ie) {
throw new SOAPException("Provider " + factoryName + " could not be instantiated: "
+ ie, ie);
} catch (IllegalAccessException iae) {
throw new SOAPException("Provider " + factoryName + " could not be instantiated: "
+ iae, iae);
return cls.cast(klass.getDeclaredConstructor().newInstance());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
throw new SOAPException("Provider " + factoryName + " could not be instantiated: " + ex, ex);
}
}

@@ -124,9 +124,9 @@ public Object readObject(MessageReader reader, Context context) throws Databindi
} else {
try {
clazz = ClassLoaderUtils.loadClass(impl, getClass());
object = clazz.newInstance();
object = clazz.getDeclaredConstructor().newInstance();
target = object;
} catch (ClassNotFoundException e) {
} catch (ClassNotFoundException | NoSuchMethodException e) {
throw new DatabindingException("Could not find implementation class " + impl
+ " for class " + clazz.getName());
}
@@ -135,8 +135,12 @@ public Object readObject(MessageReader reader, Context context) throws Databindi
object = createFromFault(context);
target = object;
} else {
object = clazz.newInstance();
target = object;
try {
object = clazz.getDeclaredConstructor().newInstance();
target = object;
} catch (NoSuchMethodException e) {
throw new DatabindingException("Could not create object of class " + clazz.getName());
}
}

// Read attributes
@@ -140,7 +140,7 @@ protected Map<Object, Object> instantiateMap() {
map = new HashMap<>();
} else {
try {
map = (Map<Object, Object>)cls.newInstance();
map = (Map<Object, Object>)cls.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new DatabindingException("Could not create map implementation: "
+ getTypeClass().getName(), e);
@@ -77,9 +77,9 @@ public void testType() throws Exception {

public static class GenericsService {

public <T extends Serializable> T createInstance(Class<T> type)
throws InstantiationException, IllegalAccessException {
return type.newInstance();
public <T extends Serializable> T createInstance(Class<T> type)
throws Exception {
return type.getDeclaredConstructor().newInstance();
}
}

@@ -664,7 +664,8 @@ public WrapperHelper createWrapperHelper(Class<?> wrapperType, QName wrapperName

Object objectFactory = null;
try {
objectFactory = wrapperType.getClassLoader().loadClass(objectFactoryClassName).newInstance();
objectFactory = wrapperType.getClassLoader().loadClass(objectFactoryClassName)
.getDeclaredConstructor().newInstance();
} catch (Exception e) {
//ignore, probably won't need it
}
@@ -763,7 +763,7 @@ private static Object createSet(MessagePartInfo part, List<Object> ret) {
}
Collection<Object> c;