Replaces the simple calls with no arguments to newInstance()

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5078 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
baka 2017-10-25 13:26:01 +00:00
parent 92e62ff6ec
commit a15eadb194
17 changed files with 109 additions and 56 deletions

View File

@ -35,6 +35,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import javax.servlet.ServletException;
@ -137,8 +138,8 @@ public class CMSPage extends Page implements ResourceHandler {
final Class<PresentationManager> presenterClass = BebopConfig.getConfig().getPresenterClass();
final PresentationManager pm;
try {
pm = presenterClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
pm = presenterClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
throw new RuntimeException(ex);
}

View File

@ -133,7 +133,7 @@ public class CMSApplicationPage extends Page {
.getConfig().getPresenterClass();
final PresentationManager presenter;
try {
presenter = presenterClass.newInstance();
presenter = presenterClass.class.getDeclaredConstructor().newInstance();
} catch (InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException("Failed to create PresentationManager",

View File

@ -108,7 +108,7 @@ public class AssetManager {
final T asset;
try {
asset = assetType.newInstance();
asset = assetType.class.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException | InstantiationException ex) {
throw new UnexpectedErrorException(ex);
}

View File

@ -230,7 +230,7 @@ public class LifecycleManager {
final Object object;
try {
object = listenerClass.newInstance();
object = listenerClass.class.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException
| InstantiationException ex) {
LOGGER.error("Failed to create instance of LifecycleEventListener "
@ -275,7 +275,7 @@ public class LifecycleManager {
final Object object;
try {
object = listenerClass.newInstance();
object = listenerClass.class.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException
| InstantiationException ex) {
LOGGER.error("Failed to create instance of PhaseEventListener "

View File

@ -45,7 +45,7 @@ public class CmsTaskManager {
.getTaskType().getUrlGenerator();
final TaskURLGenerator urlGenerator;
try {
urlGenerator = urlGeneratorClass.newInstance();
urlGenerator = urlGeneratorClass.class.getDeclaredConstructor().newInstance();
} catch (IllegalAccessException
| InstantiationException ex) {
throw new UnexpectedErrorException(ex);

View File

@ -24,6 +24,7 @@ import com.arsdigita.web.RedirectSignal;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
@ -154,7 +155,7 @@ public abstract class BaseDispatcherServlet extends HttpServlet
File file = new File(getServletContext().getRealPath(
"/WEB-INF/web.xml"));
// all we care about is the welcome-file-list element
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParserFactory spf = SAXParserFactory.class.getDeclaredConstructor().newInstance();
spf.setValidating(false);
SAXParser parser = spf.newSAXParser();
parser.parse(file, new WebXMLReader());
@ -164,6 +165,8 @@ public abstract class BaseDispatcherServlet extends HttpServlet
LOGGER.error("error in init", pce);
} catch (IOException ioe) {
LOGGER.error("error in init", ioe);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
}
// default to index.jsp, index.html
if (m_welcomeFiles.isEmpty()) {

View File

@ -30,6 +30,7 @@ import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import javax.servlet.ServletException;
@ -338,9 +339,9 @@ public class ACSObjectSelectionModel implements SingleSelectionModel {
Assert.exists(javaClassName, Class.class);
try {
final CcmObject object = (CcmObject) javaClassName.newInstance();
final CcmObject object = (CcmObject) javaClassName.getDeclaredConstructor().newInstance();
return object;
} catch (InstantiationException | IllegalAccessException ex) {
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
throw new ServletException(ex);
}
}

View File

@ -26,6 +26,7 @@ import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Date;
import java.util.Iterator;
@ -97,7 +98,7 @@ public final class XSLTemplate {
try {
LOGGER.debug("Getting new templates object");
final TransformerFactory factory = TransformerFactory.newInstance();
final TransformerFactory factory = TransformerFactory.class.getDeclaredConstructor().newInstance();
factory.setURIResolver(resolver);
factory.setErrorListener(listener);
@ -109,6 +110,9 @@ public final class XSLTemplate {
throw new WrappedTransformerException(ex);
} catch (TransformerException ex) {
throw new WrappedTransformerException(ex);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
throw new RuntimeException(e);
}
// List contains each include/import URL found in the style sheet

View File

@ -27,6 +27,8 @@ import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.LayoutPanel;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.SystemInformation;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
@ -251,29 +253,41 @@ public class SystemInformationTab extends LayoutPanel {
public String getValue() {
switch (currentIndex) {
case TRANSFORMER_FACTORY_INDEX:
return TransformerFactory.newInstance().getClass().getName();
try {
return TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case TRANSFORMER_INDEX:
try {
return TransformerFactory.newInstance().newTransformer().getClass().getName();
return TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass().getName();
} catch(TransformerConfigurationException ex) {
return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case DOCUMENT_BUILDER_FACTORY_INDEX:
return DocumentBuilderFactory.newInstance().getClass().getName();
try {
return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case DOCUMENT_BUILDER_INDEX:
try{
return DocumentBuilderFactory.newInstance().newDocumentBuilder().getClass()
return DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder().getClass()
.getName();
} catch(ParserConfigurationException ex) {
return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case SAX_PARSER_FACTORY_INDEX:
return SAXParserFactory.newInstance().getClass().getName();
try {
return SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
case SAX_PARSER_INDEX:
try {
return SAXParserFactory.newInstance().newSAXParser().getClass().getName();
return SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass().getName();
} catch(ParserConfigurationException | SAXException ex) {
return "???";
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
default:
return "";

View File

@ -34,6 +34,7 @@ import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
/**
* A wrapper class that implements some functionality of
@ -41,7 +42,7 @@ import java.io.UnsupportedEncodingException;
*
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* pboy (Jan. 09)
* Class uses "DocumentBuilderFactory.newInstance()" to setup the parser
* Class uses "DocumentBuilderFactory.class.getDeclaredConstructor().newInstance()" to setup the parser
* (according to the javax.xml specification). This is a simple and
* straightforward, but rather thumb method. It requires a JVM wide acceptable
* configuration (using a system.property or a static JRE configuration file) and
@ -116,8 +117,9 @@ public class Document {
// instead to achieve independence from a JVM wide configuration.
// Requires additional modifications in c.ad.util.xml.XML
static {
try {
LOGGER.debug("Static initalizer starting...");
s_builder = DocumentBuilderFactory.newInstance();
s_builder = DocumentBuilderFactory.class.getDeclaredConstructor().newInstance();
s_builder.setNamespaceAware(true);
s_db = new ThreadLocal() {
@ -131,6 +133,9 @@ public class Document {
}
};
LOGGER.debug("Static initalized finished.");
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
}
}
/* Used to build the DOM Documents that this class wraps */
@ -311,7 +316,7 @@ public class Document {
try {
StreamSource identitySource =
new StreamSource(new StringReader(identityXSL));
identity = TransformerFactory.newInstance().newTransformer(
identity = TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer(
identitySource);
identity.setOutputProperty("method", "xml");
identity.setOutputProperty("indent", (indent ? "yes" : "no"));
@ -320,6 +325,9 @@ public class Document {
} catch (javax.xml.transform.TransformerException e) {
LOGGER.error("error in toString", e);
return document.toString();
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
return null; // This shouldn't be possible
}
try {

View File

@ -20,10 +20,13 @@ package com.arsdigita.xml;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -32,6 +35,7 @@ import java.util.List;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Attr;
/**
* A wrapper class that implements some functionality of
* <code>org.jdom.Element</code> using <code>org.w3c.dom.Element</code>.
@ -56,7 +60,7 @@ public class Element {
public Object initialValue() {
try {
DocumentBuilderFactory builder =
DocumentBuilderFactory.newInstance();
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance();
builder.setNamespaceAware(true);
return builder.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
@ -64,6 +68,9 @@ public class Element {
throw new UncheckedWrapperException(
"INTERNAL: Could not create thread local DOM document.",
e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
return null; // This shouldn't be possible
}
}

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@ -203,7 +204,7 @@ public class XML {
// configuration (affecting all CCM instances which may run in a
// container).
// Requires additional modifications in c.ad.util.xml.XML
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParserFactory spf = SAXParserFactory.class.getDeclaredConstructor().newInstance();
spf.setFeature("http://xml.org/sax/features/namespaces", true);
SAXParser parser = spf.newSAXParser();
parser.parse(source, handler);
@ -218,6 +219,8 @@ public class XML {
}
} catch (IOException e) {
throw new UncheckedWrapperException("error parsing stream", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
}
}

View File

@ -34,6 +34,7 @@ import javax.inject.Inject;
import javax.transaction.Transactional;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -357,13 +358,16 @@ public class ConfigurationManager implements Serializable {
final T conf;
try {
conf = confClass.newInstance();
conf = confClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
LOGGER.warn(String.format(
"Failed to instantiate configuration \"%s\".",
confClass.getName()),
ex);
return null;
} catch (InvocationTargetException | NoSuchMethodException e) {
LOGGER.error(e);
return null;
}
final List<AbstractSetting> settingList = settingManager

View File

@ -29,6 +29,7 @@ import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -79,47 +80,54 @@ public class SysInfoController {
final ResourceBundle texts = ResourceBundle.getBundle(
"com.arsdigita.ui.admin.AdminResources");
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer_factory"),
TransformerFactory.newInstance().getClass().getName()));
TransformerFactory.class.getDeclaredConstructor().newInstance().getClass().getName()));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"),
TransformerFactory.newInstance().newTransformer().getClass()
TransformerFactory.class.getDeclaredConstructor().newInstance().newTransformer().getClass()
.getName()));
} catch (TransformerConfigurationException ex) {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_transformer"), "???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder_factory"),
DocumentBuilderFactory.newInstance().getClass().getName()));
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().getClass().getName()));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"),
DocumentBuilderFactory.newInstance().newDocumentBuilder()
DocumentBuilderFactory.class.getDeclaredConstructor().newInstance().newDocumentBuilder()
.getClass().getName()));
} catch (ParserConfigurationException ex) {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.xml_document_builder"),
"???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser_factory"),
SAXParserFactory.newInstance().getClass().getName()));
SAXParserFactory.class.getDeclaredConstructor().newInstance().getClass().getName()));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
try {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"),
SAXParserFactory.newInstance().newSAXParser().getClass()
SAXParserFactory.class.getDeclaredConstructor().newInstance().newSAXParser().getClass()
.getName()));
} catch (ParserConfigurationException | SAXException ex) {
xmlProps.add(new SysInfoProperty(
texts.getString("ui.admin.sysinfo.sax_parser"), "???"));
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
}
return xmlProps;

View File

@ -185,8 +185,8 @@ public class WorkflowManager {
final Class<? extends Task> templateClass = template.getClass();
final Task task;
try {
task = templateClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
task = templateClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
throw new RuntimeException(ex);
}

View File

@ -47,7 +47,7 @@ public class EntitiesTestCore {
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
final Object obj = entityClass.newInstance();
final Object obj = entityClass.class.getDeclaredConstructor().newInstance();
final Field[] fields = entityClass.getDeclaredFields();
for (Field field : fields) {

View File

@ -33,7 +33,7 @@
response.getOutputStream().print("requestURI = " + request.getRequestURI());
response.getOutputStream().print("requestURL = " + request.getRequestURL());*/
TransformerFactory factory = TransformerFactory.newInstance();
TransformerFactory factory = TransformerFactory.class.getDeclaredConstructor().newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(themeURL + "/start.xsl"));
transformer.setParameter("theme-prefix", themeURL);
transformer.transform(new StreamSource(themeURL + "/doc/foundry-documentation.xml"),