Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9dabe9a
Use StringUtils.isNotBlank to make intent clearer
FSchumacher Nov 27, 2018
5db20ea
Replace deprecated newInstance calls
FSchumacher Nov 27, 2018
9ea1b7b
Use log format string
FSchumacher Nov 27, 2018
c21bbd2
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
c4a32b8
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
90ac826
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
dc04575
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
99dfb49
Use log format strings
FSchumacher Nov 27, 2018
632a30f
Simplify code.
FSchumacher Nov 27, 2018
59646b4
Use Java conventions for names of parameters
FSchumacher Nov 27, 2018
100bf93
Use StringUtils#isNotBlank to make intent clearer
FSchumacher Nov 27, 2018
08413fb
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
f10891f
Extract code to create BackendListenerClient from a classname
FSchumacher Nov 27, 2018
e4e23ed
Extract code into private methods to make intent clearer
FSchumacher Nov 27, 2018
78f0870
Use StringUtils.isNotBlank to make intent of code clearer
FSchumacher Nov 27, 2018
2d41ba0
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
cc882df
Get rid of deprecated newInstance calls
FSchumacher Nov 27, 2018
3e7030d
Get rid of deprecated newInstance calls
FSchumacher Nov 27, 2018
ee05360
Use log string formats
FSchumacher Nov 27, 2018
d78b7c4
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
39b104c
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
92530c4
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
9f74643
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
3c8b2da
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
d117321
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
27f114f
Use log format strings
FSchumacher Nov 27, 2018
d5c50fc
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
b77206e
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
af2aa52
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
f6ffad9
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
4c34925
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
963a2d5
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
d87f390
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
14fa446
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
0b70029
Get rid of deprecated newInstance calls
FSchumacher Nov 27, 2018
b3f87a7
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
44a7e89
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
491c0bc
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
c4405d9
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
4fbb369
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
4ea758c
With varargs there is no need for an extra array
FSchumacher Nov 27, 2018
85d3b28
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
01d696a
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
9f757b6
With varargs there is no need for the arrays
FSchumacher Nov 27, 2018
b6bf0e8
Simplify code that tries to find the correct constructor
FSchumacher Nov 27, 2018
9fff08f
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
947e794
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
3c5f94a
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
fa1f103
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
f0c0706
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
0ef7c32
Get rid of deprecated newInstance call
FSchumacher Nov 27, 2018
d4c5eb8
Adapt test case to new method of constructing instances
FSchumacher Nov 28, 2018
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 @@ -63,7 +63,7 @@ public RequestPanel() {
for (String clazz : classesToAdd) {
try {
// Instantiate requestview classes
final RequestView requestView = (RequestView) Class.forName(clazz).newInstance();
final RequestView requestView = (RequestView) Class.forName(clazz).getDeclaredConstructor().newInstance();
if (rawTab.equals(requestView.getLabel())) {
rawObject = requestView; // use later
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private Component createComboRender() {
for (String clazz : classesToAdd) {
try {
// Instantiate render classes
final ResultRenderer renderer = (ResultRenderer) Class.forName(clazz).newInstance();
final ResultRenderer renderer = (ResultRenderer) Class.forName(clazz).getDeclaredConstructor().newInstance();
if (textRenderer.equals(renderer.toString())){
textObject=renderer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static BackendListenerClient createBackendListenerClientImpl(Class<?> clientClas
return new ErrorBackendListenerClient();
}
try {
return (BackendListenerClient) clientClass.newInstance();
return (BackendListenerClient) clientClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.error("Exception creating: {}", clientClass, e);
return new ErrorBackendListenerClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.JTextField;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.config.gui.ArgumentsPanel;
Expand Down Expand Up @@ -169,49 +170,16 @@ public void actionPerformed(ActionEvent event) {

String newClassName = ((String) classnameCombo.getSelectedItem()).trim();
try {
BackendListenerClient client = (BackendListenerClient) Class.forName(newClassName, true,
Thread.currentThread().getContextClassLoader()).newInstance();
BackendListenerClient oldClient = (BackendListenerClient) Class.forName(className, true,
Thread.currentThread().getContextClassLoader()).newInstance();
BackendListenerClient client = createBackendListenerClient(newClassName);
BackendListenerClient oldClient = createBackendListenerClient(className);

Arguments currArgs = new Arguments();
argsPanel.modifyTestElement(currArgs);
Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
Map<String, String> userArgMap = new HashMap<>();
userArgMap.putAll(currArgsMap);
Arguments newArgs = new Arguments();
Arguments defaultArgs = null;
try {
defaultArgs = client.getDefaultParameters();
Arguments currentUserArgs = oldClient.getDefaultParameters();
if(currentUserArgs != null) {
userArgMap.keySet().removeAll(currentUserArgs.getArgumentsAsMap().keySet());
}
} catch (AbstractMethodError e) {
log.warn("BackendListenerClient doesn't implement "
+ "getDefaultParameters. Default parameters won't "
+ "be shown. Please update your client class: {}", newClassName);
}

if (defaultArgs != null) {
for (JMeterProperty jMeterProperty : defaultArgs.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String name = arg.getName();
String value = arg.getValue();

// If a user has set parameters in one test, and then
// selects a different test which supports the same
// parameters, those parameters should have the same
// values that they did in the original test.
if (currArgsMap.containsKey(name)) {
String newVal = currArgsMap.get(name);
if (newVal != null && newVal.length() > 0) {
value = newVal;
}
}
newArgs.addArgument(name, value);
}
}
Arguments defaultArgs = extractDefaultArguments(client, userArgMap, oldClient.getDefaultParameters());
Arguments newArgs = copyDefaultArguments(currArgsMap, defaultArgs);
userArgMap.forEach(newArgs::addArgument);

className = newClassName;
Expand All @@ -222,6 +190,55 @@ public void actionPerformed(ActionEvent event) {
}
}


private Arguments copyDefaultArguments(Map<String, String> currArgsMap, Arguments defaultArgs) {
Arguments newArgs = new Arguments();
if (defaultArgs != null) {
for (JMeterProperty jMeterProperty : defaultArgs.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String name = arg.getName();
String value = arg.getValue();

// If a user has set parameters in one test, and then
// selects a different test which supports the same
// parameters, those parameters should have the same
// values that they did in the original test.
if (currArgsMap.containsKey(name)) {
String newVal = currArgsMap.get(name);
if (StringUtils.isNotBlank(newVal)) {
value = newVal;
}
}
newArgs.addArgument(name, value);
}
}
return newArgs;
}


private Arguments extractDefaultArguments(BackendListenerClient client, Map<String, String> userArgMap,
Arguments currentUserArguments) {
Arguments defaultArgs = null;
try {
defaultArgs = client.getDefaultParameters();
if(currentUserArguments != null) {
userArgMap.keySet().removeAll(currentUserArguments.getArgumentsAsMap().keySet());
}
} catch (AbstractMethodError e) {
log.warn("BackendListenerClient doesn't implement "
+ "getDefaultParameters. Default parameters won't "
+ "be shown. Please update your client class: {}", client.getClass().getName());
}
return defaultArgs;
}


private BackendListenerClient createBackendListenerClient(String newClassName)
throws ReflectiveOperationException {
return (BackendListenerClient) Class.forName(newClassName, true,
Thread.currentThread().getContextClassLoader()).getDeclaredConstructor().newInstance();
}

/**
* Create a panel containing components allowing the user to provide
* arguments to be passed to the test class instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void setupTest(BackendListenerContext context) throws Exception {
}
}
Class<?> clazz = Class.forName(graphiteMetricsSenderClass);
this.graphiteMetricsManager = (GraphiteMetricsSender) clazz.newInstance();
this.graphiteMetricsManager = (GraphiteMetricsSender) clazz.getDeclaredConstructor().newInstance();
graphiteMetricsManager.setup(graphiteHost, graphitePort, rootMetricsPrefix);
if (useRegexpForSamplersList) {
pattern = Pattern.compile(samplersList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void setupTest(BackendListenerContext context) throws Exception {
userTag = userTagBuilder.toString();

Class<?> clazz = Class.forName(influxdbMetricsSender);
this.influxdbMetricsManager = (InfluxdbMetricsSender) clazz.newInstance();
this.influxdbMetricsManager = (InfluxdbMetricsSender) clazz.getDeclaredConstructor().newInstance();
influxdbMetricsManager.setup(influxdbUrl);
samplersToFilter = Pattern.compile(samplersRegex);
addAnnotation(true);
Expand Down
2 changes: 1 addition & 1 deletion src/core/org/apache/jmeter/NewDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public static void main(String[] args) {

try {
Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$
Object instance = initialClass.newInstance();
Object instance = initialClass.getDeclaredConstructor().newInstance();
Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$
startup.invoke(instance, new Object[] { args });
} catch(Throwable e){ // NOSONAR We want to log home directory in case of exception
Expand Down
4 changes: 2 additions & 2 deletions src/core/org/apache/jmeter/engine/util/CompoundVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class CompoundVariable implements Function {
List<String> classes = ClassFinder.findClassesThatExtend(JMeterUtils.getSearchPaths(),
new Class[] { Function.class }, true, contain, notContain);
for (String clazzName : classes) {
Function tempFunc = (Function) Class.forName(clazzName).newInstance();
Function tempFunc = (Function) Class.forName(clazzName).getDeclaredConstructor().newInstance();
String referenceKey = tempFunc.getReferenceKey();
if (referenceKey.length() > 0) { // ignore self
functions.put(referenceKey, tempFunc.getClass());
Expand Down Expand Up @@ -195,7 +195,7 @@ public void setParameters(String parameters) throws InvalidVariableException {
static Object getNamedFunction(String functionName) throws InvalidVariableException {
if (functions.containsKey(functionName)) {
try {
return functions.get(functionName).newInstance();
return functions.get(functionName).getDeclaredConstructor().newInstance();
} catch (Exception e) {
log.error("Exception occurred while instantiating a function: {}", functionName, e); // $NON-NLS-1$
throw new InvalidVariableException(e);
Expand Down
10 changes: 5 additions & 5 deletions src/core/org/apache/jmeter/gui/GuiPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public TestElement createTestElement(String objClass) {
"Missing jar? See log file." ,
JOptionPane.ERROR_MESSAGE);
throw new RuntimeException(e.toString(), e); // Probably a missing jar
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch ( ReflectiveOperationException e) {
log.error("Problem retrieving gui for " + objClass, e);
throw new RuntimeException(e.toString(), e); // Programming error: bail out.
}
Expand All @@ -389,9 +389,9 @@ public TestElement createTestElement(String objClass) {
* @throws IllegalAccessException
* if access rights do not allow the default constructor to be
* called
* @throws ReflectiveOperationException when construction of guiClass fails
*/
private JMeterGUIComponent getGuiFromCache(Class<?> guiClass, Class<?> testClass) throws InstantiationException,
IllegalAccessException {
private JMeterGUIComponent getGuiFromCache(Class<?> guiClass, Class<?> testClass) throws ReflectiveOperationException {
JMeterGUIComponent comp;
if (guiClass == TestBeanGUI.class) {
comp = testBeanGUIs.get(testClass);
Expand All @@ -402,7 +402,7 @@ private JMeterGUIComponent getGuiFromCache(Class<?> guiClass, Class<?> testClass
} else {
comp = guis.get(guiClass);
if (comp == null) {
comp = (JMeterGUIComponent) guiClass.newInstance();
comp = (JMeterGUIComponent) guiClass.getDeclaredConstructor().newInstance();
if (!(comp instanceof UnsharedComponent)) {
guis.put(guiClass, comp);
}
Expand Down Expand Up @@ -909,7 +909,7 @@ public TreeNodeNamingPolicy getNamingPolicy() {

try {
Class<?> implementationClass = Class.forName(namingPolicyImplementation);
this.namingPolicy = (TreeNodeNamingPolicy) implementationClass.newInstance();
this.namingPolicy = (TreeNodeNamingPolicy) implementationClass.getDeclaredConstructor().newInstance();

} catch (Exception ex) {
log.error("Failed to create configured naming policy:" + namingPolicyImplementation + ", will use default one", ex);
Expand Down
2 changes: 1 addition & 1 deletion src/core/org/apache/jmeter/gui/action/ActionRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void populateCommandMap() {
}
for (String strClassName : listClasses) {
Class<?> commandClass = Class.forName(strClassName);
Command command = (Command) commandClass.newInstance();
Command command = (Command) commandClass.getDeclaredConstructor().newInstance();
for (String commandName : command.getActionNames()) {
Set<Command> commandObjects = commands.computeIfAbsent(commandName, k -> new HashSet<>());
commandObjects.add(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ private void addNodesToTreeHierachically(GuiPackage guiPackage,
* @param guiPackage {@link GuiPackage}
* @param parentNode {@link JMeterTreeNode}
* @return array of {@link JMeterTreeNode}
* @throws IllegalUserActionException
* @throws ReflectiveOperationException when class instantiation for {@value #DEFAULT_IMPLEMENTATION} fails
* @throws IllegalUserActionException when {@link ThinkTimeCreator#createThinkTime(GuiPackage, JMeterTreeNode)} throws this
*/
private JMeterTreeNode[] createThinkTime(GuiPackage guiPackage, JMeterTreeNode parentNode)
throws Exception {
private JMeterTreeNode[] createThinkTime(GuiPackage guiPackage, JMeterTreeNode parentNode)
throws ReflectiveOperationException, IllegalUserActionException {
Class<?> clazz = Class.forName(DEFAULT_IMPLEMENTATION);
ThinkTimeCreator thinkTimeCreator = (ThinkTimeCreator) clazz.newInstance();
ThinkTimeCreator thinkTimeCreator = (ThinkTimeCreator) clazz.getDeclaredConstructor().newInstance();
return thinkTimeCreator.createThinkTime(guiPackage, parentNode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private List<MenuCreator> findMenuCreators() {
Class<?> commandClass = Class.forName(strClassName);
if (!Modifier.isAbstract(commandClass.getModifiers())) {
log.debug("Instantiating: {}", commandClass);
MenuCreator creator = (MenuCreator) commandClass.newInstance();
MenuCreator creator = (MenuCreator) commandClass.getDeclaredConstructor().newInstance();
creators.add(creator);
}
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/org/apache/jmeter/gui/util/MenuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static JMeterGUIComponent getGUIComponent(
|| (testBeanGUI.isExpert() && !JMeterUtils.isExpertMode());
item = testBeanGUI;
} else {
item = (JMeterGUIComponent) c.newInstance();
item = (JMeterGUIComponent) c.getDeclaredConstructor().newInstance();
}
} catch (NoClassDefFoundError e) {
log.warn("Configuration error, probably corrupt or missing third party library(jar)? Could not create class: {}.",
Expand Down
Loading