Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public NodeState next() {
protected AbstractQueryImpl createQueryInstance() throws RepositoryException {
try {
String queryImplClassName = handler.getQueryClass();
Object obj = Class.forName(queryImplClassName).newInstance();
Object obj = Class.forName(queryImplClassName).getDeclaredConstructor().newInstance();
if (obj instanceof AbstractQueryImpl) {
return (AbstractQueryImpl) obj;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.apache.jackrabbit.core.config;


import java.lang.reflect.InvocationTargetException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,12 +41,12 @@ public Object newInstance(Class<?> klass, BeanConfig config) throws Configuratio
}

// Instantiate the object using the default constructor
return objectClass.newInstance();
return objectClass.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException e) {
throw new ConfigurationException(
"Configured bean implementation class " + cname
+ " was not found.", e);
} catch (InstantiationException e) {
} catch (InstantiationException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException e) {
throw new ConfigurationException(
"Configured bean implementation class " + cname
+ " can not be instantiated.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ public ExcerptProvider createExcerptProvider(Query query)
throws IOException {
ExcerptProvider ep;
try {
ep = (ExcerptProvider) excerptProviderClass.newInstance();
ep = (ExcerptProvider) excerptProviderClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw Util.createIOException(e);
}
Expand Down Expand Up @@ -1307,7 +1307,7 @@ protected SynonymProvider createSynonymProvider() {
SynonymProvider sp = null;
if (synonymProviderClass != null) {
try {
sp = (SynonymProvider) synonymProviderClass.newInstance();
sp = (SynonymProvider) synonymProviderClass.getDeclaredConstructor().newInstance();
sp.initialize(createSynonymProviderConfigResource());
} catch (Exception e) {
log.warn("Exception initializing synonym provider: "
Expand All @@ -1331,7 +1331,7 @@ protected DirectoryManager createDirectoryManager()
throw new IOException(directoryManagerClass +
" is not a DirectoryManager implementation");
}
DirectoryManager df = (DirectoryManager) clazz.newInstance();
DirectoryManager df = (DirectoryManager) clazz.getDeclaredConstructor().newInstance();
df.init(this);
return df;
} catch (IOException e) {
Expand All @@ -1356,7 +1356,7 @@ protected RedoLogFactory createRedoLogFactory() throws IOException {
throw new IOException(redoLogFactoryClass +
" is not a RedoLogFactory implementation");
}
return (RedoLogFactory) clazz.newInstance();
return (RedoLogFactory) clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
IOException ex = new IOException();
ex.initCause(e);
Expand Down Expand Up @@ -1420,7 +1420,7 @@ protected SpellChecker createSpellChecker() {
SpellChecker spCheck = null;
if (spellCheckerClass != null) {
try {
spCheck = (SpellChecker) spellCheckerClass.newInstance();
spCheck = (SpellChecker) spellCheckerClass.getDeclaredConstructor().newInstance();
spCheck.init(this);
} catch (Exception e) {
log.warn("Exception initializing spell checker: "
Expand Down Expand Up @@ -2422,7 +2422,7 @@ public String getSynonymProviderConfigPath() {
public void setSimilarityClass(String className) {
try {
Class<?> similarityClass = Class.forName(className);
similarity = (Similarity) similarityClass.newInstance();
similarity = (Similarity) similarityClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.warn("Invalid Similarity class: " + className, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.core.security.principal;

import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -128,17 +129,11 @@ private PrincipalProvider createProvider(Properties config)
}

try {
Class pc = Class.forName(className, true, BeanConfig.getDefaultClassLoader());
PrincipalProvider pp = (PrincipalProvider) pc.newInstance();
Class<?> pc = Class.forName(className, true, BeanConfig.getDefaultClassLoader());
PrincipalProvider pp = (PrincipalProvider) pc.getDeclaredConstructor().newInstance();
pp.init(config);
return pp;
} catch (ClassNotFoundException e) {
throw new RepositoryException("Unable to create new principal provider.", e);
} catch (IllegalAccessException e) {
throw new RepositoryException("Unable to create new principal provider.", e);
} catch (InstantiationException e) {
throw new RepositoryException("Unable to create new principal provider.", e);
} catch (ClassCastException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new RepositoryException("Unable to create new principal provider.", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class DirectoryManagerTest extends TestCase {

private static final Collection IMPLEMENTATIONS = Arrays.asList(
private static final Collection<Class<?>> IMPLEMENTATIONS = Arrays.asList(
new Class[]{FSDirectoryManager.class, RAMDirectoryManager.class});

private static final SearchIndex INDEX = new SearchIndex();
Expand Down Expand Up @@ -91,9 +91,9 @@ public void call(DirectoryManager directoryManager) throws Exception {
}

private void execute(Callable callable) throws Exception {
for (Iterator it = IMPLEMENTATIONS.iterator(); it.hasNext(); ) {
Class clazz = (Class) it.next();
DirectoryManager dirMgr = (DirectoryManager) clazz.newInstance();
for (Iterator<Class<?>> it = IMPLEMENTATIONS.iterator(); it.hasNext(); ) {
Class<?> clazz = it.next();
DirectoryManager dirMgr = (DirectoryManager) clazz.getDeclaredConstructor().newInstance();
dirMgr.init(INDEX);
try {
callable.call(dirMgr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.core.util.db;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
Expand Down Expand Up @@ -286,18 +287,15 @@ private DataSource getJndiDataSource(
Class<Context> contextClass, String name)
throws RepositoryException {
try {
Object object = contextClass.newInstance().lookup(name);
Object object = contextClass.getDeclaredConstructor().newInstance().lookup(name);
if (object instanceof DataSource) {
return (DataSource) object;
} else {
throw new RepositoryException(
"Object " + object + " with JNDI name "
+ name + " is not a JDBC DataSource");
}
} catch (InstantiationException e) {
throw new RepositoryException(
"Invalid JNDI context: " + contextClass.getName(), e);
} catch (IllegalAccessException e) {
} catch (InstantiationException|IllegalAccessException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException e) {
throw new RepositoryException(
"Invalid JNDI context: " + contextClass.getName(), e);
} catch (NamingException e) {
Expand Down Expand Up @@ -328,7 +326,7 @@ private BasicDataSource getDriverDataSource(
// The JDBC specification recommends the Class.forName
// method without the .newInstance() method call,
// but it is required after a Derby 'shutdown'
instance = (Driver) driverClass.newInstance();
instance = (Driver) driverClass.getDeclaredConstructor().newInstance();
} catch (Throwable e) {
// Ignore exceptions as there's no requirement for
// a JDBC driver class to have a public default constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Repository getRepository(@SuppressWarnings("rawtypes") Map parameters) th
Class<?> repositoryFactoryClass = Class.forName(repositoryFactoryName, true,
Thread.currentThread().getContextClassLoader());

repositoryFactory = repositoryFactoryClass.newInstance();
repositoryFactory = repositoryFactoryClass.getDeclaredConstructor().newInstance();
}
catch (Exception e) {
throw new RepositoryException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -91,14 +92,10 @@ ProtectedItemRemoveHandler createHandler(String className) {
if (!className.isEmpty()) {
Class<?> irHandlerClass = Class.forName(className);
if (ProtectedItemRemoveHandler.class.isAssignableFrom(irHandlerClass)) {
irHandler = (ProtectedItemRemoveHandler) irHandlerClass.newInstance();
irHandler = (ProtectedItemRemoveHandler) irHandlerClass.getDeclaredConstructor().newInstance();
}
}
} catch (ClassNotFoundException e) {
log.error(e.getMessage(), e);
} catch (InstantiationException e) {
log.error(e.getMessage(), e);
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error(e.getMessage(), e);
}
return irHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private static Object buildClassFromConfig(Element parent) {
String className = DomUtil.getAttribute(classElem, "name", null);
if (className != null) {
Class<?> c = Class.forName(className);
instance = c.newInstance();
instance = c.getDeclaredConstructor().newInstance();
} else {
log.error("Invalid configuration: missing 'class' element");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected RepositoryFactory getRepositoryFactory()
fail("Property '" + RepositoryStub.REPOSITORY_FACTORY + "' is not defined.");
} else {
try {
return (RepositoryFactory) Class.forName(className).newInstance();
return (RepositoryFactory) Class.forName(className).getDeclaredConstructor().newInstance();
} catch (Exception e) {
fail(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static RepositoryServiceFactory getServiceFactory(Map<?, ?> parameters)
serviceFactoryClass = Class.forName(serviceFactoryName);
}

Object serviceFactory = serviceFactoryClass.newInstance();
Object serviceFactory = serviceFactoryClass.getDeclaredConstructor().newInstance();

if (serviceFactory instanceof RepositoryServiceFactory) {
log.debug("Found RepositoryServiceFactory {}", serviceFactory);
Expand Down Expand Up @@ -248,7 +248,7 @@ public int getPollTimeout() {
public <T> T getConfiguration(String name, T defaultValue) {
if (parameters.containsKey(name)) {
Object value = parameters.get(name);
Class clazz = (defaultValue == null)
Class<?> clazz = (defaultValue == null)
? value.getClass()
: defaultValue.getClass();
if (clazz.isAssignableFrom(value.getClass())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtabl
}
String repositoryConfigClassName = (String)((StringRefAddr)rclas).getContent();

Object rof = Class.forName(configFactoryClassName).newInstance();
Object rof = Class.forName(configFactoryClassName).getDeclaredConstructor().newInstance();

if (! (rof instanceof ObjectFactory)) {
throw new Exception(rof + " must implement ObjectFactory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static AccessControlProvider newInstance(RepositoryConfig config) throws
try {
Class<?> acProviderClass = Class.forName(className);
if (AccessControlProvider.class.isAssignableFrom(acProviderClass)) {
AccessControlProvider acProvider = (AccessControlProvider) acProviderClass.newInstance();
AccessControlProvider acProvider = (AccessControlProvider) acProviderClass.getDeclaredConstructor().newInstance();
acProvider.init(config);
return acProvider;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ protected FileSystemManager createFileSystemManager() throws RepositoryException
fileSystemManager = new StandardFileSystemManager();
} else {
final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
fileSystemManager = (FileSystemManager) mgrClass.newInstance();
fileSystemManager = (FileSystemManager) mgrClass.getDeclaredConstructor().newInstance();
}

if (fileSystemManager instanceof DefaultFileSystemManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ protected FileSystemManager createFileSystemManager() throws FileSystemException
fileSystemManager = new StandardFileSystemManager();
} else {
final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
fileSystemManager = (FileSystemManager) mgrClass.newInstance();
fileSystemManager = (FileSystemManager) mgrClass.getDeclaredConstructor().newInstance();
}

if (fileSystemManager instanceof DefaultFileSystemManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;

/**
Expand Down Expand Up @@ -68,13 +69,10 @@ private ReportType(String localName, Namespace namespace, String key, Class<? ex
*/
public Report createReport(DeltaVResource resource, ReportInfo info) throws DavException {
try {
Report report = reportClass.newInstance();
Report report = reportClass.getDeclaredConstructor().newInstance();
report.init(resource, info);
return report;
} catch (IllegalAccessException e) {
// should never occur
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create new report (" + reportClass.getName() + ") from class: " + e.getMessage());
} catch (InstantiationException e) {
} catch (IllegalAccessException|InstantiationException|IllegalArgumentException|InvocationTargetException|NoSuchMethodException|SecurityException e) {
// should never occur
throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create new report (" + reportClass.getName() + ") from class: " + e.getMessage());
}
Expand Down