From 5ae71f6bf17892ae487d0368b819b0b68d123de4 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 13:27:02 +0300 Subject: [PATCH 01/40] Add Error Prone code style verification See https://errorprone.info/ It allows to capture errors like mising switch case branches, missing override, non-static inner class, etc The verification can be run locally via ./gradlew -PenableErrorprone classes Note: Java 11+ is required --- .github/workflows/main.yml | 18 ++++++++++++++++++ build.gradle.kts | 36 ++++++++++++++++++++++++++++++++++++ checksum.xml | 12 ++++++++++++ gradle.properties | 2 ++ settings.gradle.kts | 1 + 5 files changed, 69 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83c7f53618e..3850f04c9d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,3 +46,21 @@ jobs: job-id: jdk14 multi-cache-enabled: false arguments: --scan --no-parallel build -x distTar -x distTarSource -Dskip.test_TestDNSCacheManager.testWithCustomResolverAnd1Server=true + + errorprone: + name: 'Error Prone (JDK 11)' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 50 + - name: 'Set up JDK 11' + uses: actions/setup-java@v1 + with: + java-version: 11 + - uses: burrunan/gradle-cache-action@v1 + name: Test + with: + job-id: errprone + multi-cache-enabled: false + arguments: --scan --no-parallel --no-daemon -PenableErrorprone classes diff --git a/build.gradle.kts b/build.gradle.kts index 2bbc5f45b5d..45e554e6b19 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,6 +24,7 @@ import com.github.vlsi.gradle.git.dsl.gitignore import com.github.vlsi.gradle.properties.dsl.lastEditYear import com.github.vlsi.gradle.properties.dsl.props import com.github.vlsi.gradle.release.RepositoryType +import net.ltgt.gradle.errorprone.errorprone import org.ajoberstar.grgit.Grgit import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.sonarqube.gradle.SonarQubeProperties @@ -36,6 +37,7 @@ plugins { id("org.nosphere.apache.rat") id("com.github.autostyle") id("com.github.spotbugs") + id("net.ltgt.errorprone") apply false id("org.sonarqube") id("com.github.vlsi.crlf") id("com.github.vlsi.gradle-extensions") @@ -147,9 +149,11 @@ val jacocoEnabled by extra { // Do not enable spotbugs by default. Execute it only when -Pspotbugs is present val enableSpotBugs = props.bool("spotbugs", default = false) +val enableErrorprone by props() val ignoreSpotBugsFailures by props() val skipCheckstyle by props() val skipAutostyle by props() +val werror by props(true) // treat javac warnings as errors // Allow to skip building source/binary distributions val skipDist by extra { boolProp("skipDist") ?: false @@ -381,6 +385,34 @@ allprojects { dependsOn("checkstyleAll") } } + + if (enableErrorprone) { + apply(plugin = "net.ltgt.errorprone") + dependencies { + "errorprone"("com.google.errorprone:error_prone_core:${"errorprone".v}") + "annotationProcessor"("com.google.guava:guava-beta-checker:1.0") + } + tasks.withType().configureEach { + options.errorprone { + disableWarningsInGeneratedCode.set(true) + errorproneArgs.add("-XepExcludedPaths:.*/javacc/.*") + disable( + "ComplexBooleanConstant", + "EqualsGetClass", + "OperatorPrecedence", + "MutableConstantField", + // "ReferenceEquality", + "SameNameButDifferent", + "TypeParameterUnusedInFormals" + ) + // Analyze issues, and enable the check + disable( + "BigDecimalEquals", + "StringSplitter" + ) + } + } + } } plugins.withId("groovy") { if (!skipAutostyle) { @@ -468,6 +500,10 @@ allprojects { tasks { withType().configureEach { options.encoding = "UTF-8" + options.compilerArgs.add("-Xlint:deprecation") + if (werror) { + options.compilerArgs.add("-Werror") + } } withType().configureEach { filteringCharset = "UTF-8" diff --git a/checksum.xml b/checksum.xml index acec18f2ef7..6891cafe094 100644 --- a/checksum.xml +++ b/checksum.xml @@ -12,12 +12,17 @@ + + + + + @@ -28,7 +33,9 @@ + + @@ -144,6 +151,7 @@ + @@ -152,6 +160,7 @@ + @@ -188,6 +197,9 @@ CB312B3F571D91EF183C119D878F50464FFD97F853B7311CBA386463F295E8B7B3A5A89ED4269A045CACD5AA7CB4C803D4882854A0FDDEFA9BBC28C72AA6C786 + + DC1FA477AE67F94B7CA427F1F88FD3C56E562EB3ED92A3CBC4CC116258EB3856F4B53C99506FDC279F6983EAE74BA21271E4A152F5DB8B41392FFCBB6B087C78 + 16D30BE564723B74F312B4E7D06F349370FB6726B3162778C869CD723ECA2A40C4972C2757B3E107E1820CEC0D70B0BD2B96EFCD466518FC64495F7AEF97967A diff --git a/gradle.properties b/gradle.properties index 131226a6cca..a585d227625 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,6 +34,7 @@ jmeter.version=5.3.1 # Tools checkstyle.version=8.35 +errorprone.version=2.4.0 jacoco.version=0.8.5 spotbugs.version=4.1.2 velocity.version=1.7 @@ -44,6 +45,7 @@ com.github.spotbugs.version=4.5.0 com.github.vlsi.checksum-dependency.sha512=4D1A76F38F327CEA0C723D9BDD9ABFE16933769052F47BCECD555DDD1A6CD0A9C21E3CC8F9E1B92780F9B443070D4844889EE9ECB0690D30E50AAB085096D8E1 com.github.vlsi.checksum-dependency.version=1.70 com.github.vlsi.vlsi-release-plugins.version=1.70 +net.ltgt.errorprone.version=1.2.1 org.jetbrains.gradle.plugin.idea-ext.version=0.5 org.nosphere.apache.rat.version=0.7.0 org.sonarqube.version=3.0 diff --git a/settings.gradle.kts b/settings.gradle.kts index df160ae6f23..e8bb2056323 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,6 +26,7 @@ pluginManagement { idv("com.github.vlsi.gradle-extensions", "com.github.vlsi.vlsi-release-plugins") idv("com.github.vlsi.ide", "com.github.vlsi.vlsi-release-plugins") idv("com.github.vlsi.stage-vote-release", "com.github.vlsi.vlsi-release-plugins") + idv("net.ltgt.errorprone") idv("org.jetbrains.gradle.plugin.idea-ext") idv("org.nosphere.apache.rat") idv("org.sonarqube") From 43217ec8086c8f2dc485936cd020c9c8107b698e Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 14:45:19 +0300 Subject: [PATCH 02/40] Remove LoggingManager class (it has been deprecated since JMeter 3.2) --- extras/startup.bsh | 4 +- .../AbstractBackendListenerClient.java | 15 -- .../jorphan/logging/LoggingManager.java | 228 ------------------ .../jorphan/logging/Slf4jLogkitLogger.java | 163 ------------- .../sampler/AbstractJavaSamplerClient.java | 16 -- xdocs/changes.xml | 1 + 6 files changed, 3 insertions(+), 424 deletions(-) delete mode 100644 src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java delete mode 100644 src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java diff --git a/extras/startup.bsh b/extras/startup.bsh index 9032cb193cf..663b83881d7 100644 --- a/extras/startup.bsh +++ b/extras/startup.bsh @@ -33,7 +33,6 @@ bsh.system.shutdownOnExit = false; print("Startup script running"); import org.apache.jmeter.util.JMeterUtils; -import org.apache.jorphan.logging.LoggingManager; getprop(p){// get a JMeter property return JMeterUtils.getPropDefault(p,""); @@ -49,7 +48,8 @@ print(p + " = " + getprop(p)); } loglevel(String priority, String category){ -LoggingManager.setPriority(priority, category); +// Previous implementation delegated the call to LoggingManager which +// was deprecated since JMeter 3.2 } logdebug(String text){ diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/AbstractBackendListenerClient.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/AbstractBackendListenerClient.java index 0b57b5a3cb0..823a515c606 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/AbstractBackendListenerClient.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/AbstractBackendListenerClient.java @@ -54,9 +54,6 @@ public abstract class AbstractBackendListenerClient implements BackendListenerCl private static final Logger log = LoggerFactory.getLogger(AbstractBackendListenerClient.class); - @SuppressWarnings("deprecation") // will be removed in 3.3 - private static final org.apache.log.Logger oldLogger = org.apache.jorphan.logging.LoggingManager.getLoggerForClass(); - private UserMetric userMetrics = new UserMetric(); private ConcurrentHashMap metricsPerSampler = new ConcurrentHashMap<>(); @@ -87,18 +84,6 @@ public Arguments getDefaultParameters() { return null; } - /** - * Get a Logger instance which can be used by subclasses to log information. - * As this class is designed to be subclassed this is useful. - * - * @return a Logger instance which can be used for logging - * @deprecated Will be removed in 3.3, use {@link AbstractBackendListenerClient#getNewLogger()} - */ - @Deprecated - protected org.apache.log.Logger getLogger() { - return oldLogger; - } - /** * Get a Logger instance which can be used by subclasses to log information. * As this class is designed to be subclassed this is useful. diff --git a/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java b/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java deleted file mode 100644 index 0bd44cc4edd..00000000000 --- a/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jorphan.logging; - -import java.util.Properties; - -import org.apache.log.LogTarget; -import org.apache.log.Logger; -import org.apache.log.Priority; -import org.slf4j.LoggerFactory; - -/** - * Manages JMeter logging - * @deprecated since 3.2, use SLF4J for logger creation - */ -@Deprecated -public final class LoggingManager { - - /** - * Predefined format patterns, selected by the property log_format_type (see - * jmeter.properties) The new-line is added later - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static final String DEFAULT_PATTERN = "%{time:yyyy/MM/dd HH:mm:ss} %5.5{priority} - " //$NON_NLS-1$ - + "%{category}: %{message} %{throwable}"; //$NON_NLS-1$ - - /** - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static final String LOG_FILE = "log_file"; //$NON_NLS-1$ - - /** - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static final String LOG_PRIORITY = "log_level"; //$NON_NLS-1$ - - private LoggingManager() { - // non-instantiable - static methods only - } - - /** - * Initialise the logging system from the Jmeter properties. Logkit loggers - * inherit from their parents. - * - * Normally the jmeter properties file defines a single log file, so set - * this as the default from "log_file", default "jmeter.log" The default - * priority is set from "log_level", with a default of INFO - * - * @param properties - * {@link Properties} to be used for initialization - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void initializeLogging(Properties properties) { - // NOP - } - - /** - * Handle LOG_PRIORITY.category=priority and LOG_FILE.category=file_name - * properties. If the prefix is detected, then remove it to get the - * category. - * - * @param appProperties - * {@link Properties} that contain the - * {@link LoggingManager#LOG_PRIORITY LOG_PRIORITY} and - * {@link LoggingManager#LOG_FILE LOG_FILE} prefixed entries - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setLoggingLevels(Properties appProperties) { - // NOP - } - - /** - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - private static final String PACKAGE_PREFIX = "org.apache."; //$NON_NLS-1$ - - /** - * Removes the standard prefix, i.e. "org.apache.". - * - * @param name from which to remove the prefix - * @return the name with the prefix removed - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static String removePrefix(String name){ - if (name.startsWith(PACKAGE_PREFIX)) { // remove the package prefix - name = name.substring(PACKAGE_PREFIX.length()); - } - return name; - } - - /** - * Get the Logger for a class - no argument needed because the calling class - * name is derived automatically from the call stack. - * - * @return Logger - */ - public static Logger getLoggerForClass() { - String className = new Exception().getStackTrace()[1].getClassName(); - return new Slf4jLogkitLogger(LoggerFactory.getLogger(className)); - } - - /** - * Get the Logger for a class. - * - * @param category - the full name of the logger category - * - * @return Logger - */ - public static Logger getLoggerFor(String category) { - return new Slf4jLogkitLogger(LoggerFactory.getLogger(category)); - } - - /** - * Get the Logger for a class. - * - * @param category - the full name of the logger category, this will have the prefix removed. - * - * @return Logger - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static Logger getLoggerForShortName(String category) { - return getLoggerFor(category); - } - - /** - * Set the logging priority for a category. - * - * @param priority - string containing the priority name, e.g. "INFO", "WARN", "DEBUG", "FATAL_ERROR" - * @param category - string containing the category - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setPriority(String priority, String category) { - // NOP - } - - /** - * Set the logging priority for a category. - * - * @param priority - priority, e.g. DEBUG, INFO - * @param fullName - e.g. org.apache.jmeter.etc, will have the prefix removed. - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setPriorityFullName(String priority, String fullName) { - // NOP - } - - /** - * Set the logging priority for a category. - * - * @param priority - e.g. Priority.DEBUG - * @param category - string containing the category - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setPriority(Priority priority, String category) { - // NOP - } - - /** - * Set the logging priority. - * - * @param priority - e.g. Priority.DEBUG - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setPriority(String priority) { - // NOP - } - - /** - * Set the default logging priority. - * - * @param priority e.g. Priority.DEBUG - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setPriority(Priority priority) { - // NOP - } - - /** - * Set the logging target for a category. - * - * @param target the LogTarget - * @param category the category name - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void setTarget(LogTarget target, String category) { - // NOP - } - - /** - * Add logTargets to root logger - * FIXME What's the clean way to add a LogTarget afterwards ? - * @param logTargets LogTarget array - * @deprecated since 3.2, use SLF4J for logging - */ - @Deprecated - public static void addLogTargetToRootLogger(LogTarget[] logTargets) { - // NOP - } -} diff --git a/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java b/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java deleted file mode 100644 index f3e373c52fb..00000000000 --- a/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jorphan.logging; - -import org.apache.log.Priority; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Wrapper, implementing org.apache.log.Logger and delegating to the internal SLF4J logger. - */ -@Deprecated // Logger & Priority will be dropped in 3.3; so will this class be -class Slf4jLogkitLogger extends org.apache.log.Logger { - - private final Logger slf4jLogger; - - Slf4jLogkitLogger(final Logger slf4jLogger) { - this.slf4jLogger = slf4jLogger; - } - - @Override - public boolean isDebugEnabled() { - return slf4jLogger.isDebugEnabled(); - } - - @Override - public void debug(String message, Throwable throwable) { - slf4jLogger.debug(message, throwable); - } - - @Override - public void debug(String message) { - slf4jLogger.debug(message); - } - - @Override - public boolean isInfoEnabled() { - return slf4jLogger.isInfoEnabled(); - } - - @Override - public void info(String message, Throwable throwable) { - slf4jLogger.info(message, throwable); - } - - @Override - public void info(String message) { - slf4jLogger.info(message); - } - - @Override - public boolean isWarnEnabled() { - return slf4jLogger.isWarnEnabled(); - } - - @Override - public void warn(String message, Throwable throwable) { - slf4jLogger.warn(message, throwable); - } - - @Override - public void warn(String message) { - slf4jLogger.warn(message); - } - - @Override - public boolean isErrorEnabled() { - return slf4jLogger.isErrorEnabled(); - } - - @Override - public void error(String message, Throwable throwable) { - slf4jLogger.error(message, throwable); - } - - @Override - public void error(String message) { - slf4jLogger.error(message); - } - - @Override - public boolean isFatalErrorEnabled() { - return slf4jLogger.isErrorEnabled(); - } - - @Override - public void fatalError(String message, Throwable throwable) { - slf4jLogger.error(message, throwable); - } - - @Override - public void fatalError(String message) { - slf4jLogger.error(message); - } - - @Override - public boolean isPriorityEnabled(Priority priority) { - if (priority == Priority.FATAL_ERROR) { - return slf4jLogger.isErrorEnabled(); - } else if (priority == Priority.ERROR) { - return slf4jLogger.isErrorEnabled(); - } else if (priority == Priority.WARN) { - return slf4jLogger.isWarnEnabled(); - } else if (priority == Priority.INFO) { - return slf4jLogger.isInfoEnabled(); - } else if (priority == Priority.DEBUG) { - return slf4jLogger.isDebugEnabled(); - } - - return false; - } - - @Override - public void log(Priority priority, String message, Throwable throwable) { - if (priority == Priority.FATAL_ERROR) { - slf4jLogger.error(message, throwable); - } else if (priority == Priority.ERROR) { - slf4jLogger.error(message, throwable); - } else if (priority == Priority.WARN) { - slf4jLogger.warn(message, throwable); - } else if (priority == Priority.INFO) { - slf4jLogger.info(message, throwable); - } else if (priority == Priority.DEBUG) { - slf4jLogger.debug(message, throwable); - } - } - - @Override - public void log(Priority priority, String message) { - if (priority == Priority.FATAL_ERROR) { - slf4jLogger.error(message); - } else if (priority == Priority.ERROR) { - slf4jLogger.error(message); - } else if (priority == Priority.WARN) { - slf4jLogger.warn(message); - } else if (priority == Priority.INFO) { - slf4jLogger.info(message); - } else if (priority == Priority.DEBUG) { - slf4jLogger.debug(message); - } - } - - @Override - public org.apache.log.Logger getChildLogger(String subCategory) { - return new Slf4jLogkitLogger(LoggerFactory - .getLogger(slf4jLogger.getName() + org.apache.log.Logger.CATEGORY_SEPARATOR + subCategory)); - } -} diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/AbstractJavaSamplerClient.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/AbstractJavaSamplerClient.java index 5f0bebc1478..2bde2c62e56 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/AbstractJavaSamplerClient.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/AbstractJavaSamplerClient.java @@ -51,9 +51,6 @@ public abstract class AbstractJavaSamplerClient implements JavaSamplerClient { private static final Logger log = LoggerFactory.getLogger(AbstractJavaSamplerClient.class); - @SuppressWarnings("deprecation") // will be removed in 3.3 - private static final org.apache.log.Logger oldLogger = org.apache.jorphan.logging.LoggingManager.getLoggerForClass(); - /* Implements JavaSamplerClient.setupTest(JavaSamplerContext) */ @Override public void setupTest(JavaSamplerContext context) { @@ -72,19 +69,6 @@ public Arguments getDefaultParameters() { return null; } - /** - * Get a Logger instance which can be used by subclasses to log information. - * This is the same Logger which is used by the base JavaSampler classes - * (jmeter.protocol.java). - * - * @return a Logger instance which can be used for logging - * @deprecated Will be removed in 3.3, use {@link AbstractJavaSamplerClient#getNewLogger()} - */ - @Deprecated - protected org.apache.log.Logger getLogger() { - return oldLogger; - } - /** * Get a Logger instance which can be used by subclasses to log information. * This is the same Logger which is used by the base JavaSampler classes diff --git a/xdocs/changes.xml b/xdocs/changes.xml index ec939559035..4376fcc150c 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -74,6 +74,7 @@ applications when JMeter is starting up.

Incompatible changes
    +
  • Remove LoggingManager class (it has been deprecated since JMeter 3.2)
From 797f9e4db0a4c2feda255db5e78dbe0d054e93e2 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 14:55:27 +0300 Subject: [PATCH 03/40] Use UTF-8 encoding in BeanShellClient instead of platform-specific one --- .../java/org/apache/jmeter/util/BeanShellClient.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bshclient/src/main/java/org/apache/jmeter/util/BeanShellClient.java b/src/bshclient/src/main/java/org/apache/jmeter/util/BeanShellClient.java index 081fe5f6d2a..207009bd905 100644 --- a/src/bshclient/src/main/java/org/apache/jmeter/util/BeanShellClient.java +++ b/src/bshclient/src/main/java/org/apache/jmeter/util/BeanShellClient.java @@ -17,12 +17,14 @@ package org.apache.jmeter.util; -import java.io.FileReader; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; // N.B. Do not call any JMeter methods; the jar is standalone @@ -65,7 +67,7 @@ public static void main(String [] args) throws Exception{ sendLine("};", os); int b; - try (InputStreamReader fis = new FileReader(file)) { + try (BufferedReader fis = Files.newBufferedReader(Paths.get(file))) { while ((b = fis.read()) != -1) { os.write(b); } @@ -80,7 +82,7 @@ public static void main(String [] args) throws Exception{ private static void sendLine( String line, OutputStream outPipe ) throws IOException { - outPipe.write( line.getBytes() ); // TODO - charset? + outPipe.write(line.getBytes(StandardCharsets.UTF_8)); outPipe.flush(); } @@ -93,6 +95,7 @@ public SockRead(InputStream _is) { } @Override + @SuppressWarnings("CatchAndPrintStackTrace") public void run(){ System.out.println("Reading responses from server ..."); int x = 0; From f6b1bfa22bff3a3e5ec618122b50236c3568d6ff Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 14:57:00 +0300 Subject: [PATCH 04/40] Add JavaDoc summaries to RandomVariableConfig, CounterConfig, JavaSamplerContext, DynamicClassLoader --- .../apache/jmeter/config/RandomVariableConfig.java | 13 +++++++++++++ .../org/apache/jmeter/modifiers/CounterConfig.java | 4 +++- .../java/org/apache/jmeter/DynamicClassLoader.java | 2 +- .../protocol/java/sampler/JavaSamplerContext.java | 10 ++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/config/RandomVariableConfig.java b/src/components/src/main/java/org/apache/jmeter/config/RandomVariableConfig.java index 3651dc8c4b2..478aae865b5 100644 --- a/src/components/src/main/java/org/apache/jmeter/config/RandomVariableConfig.java +++ b/src/components/src/main/java/org/apache/jmeter/config/RandomVariableConfig.java @@ -142,6 +142,7 @@ private String formatNumber(long value){ } /** + * Returns the minimum value (inclusive). * @return the minValue */ public synchronized String getMinimumValue() { @@ -149,6 +150,7 @@ public synchronized String getMinimumValue() { } /** + * Configures the minimum value (inclusive). * @param minValue the minValue to set */ public synchronized void setMinimumValue(String minValue) { @@ -156,6 +158,7 @@ public synchronized void setMinimumValue(String minValue) { } /** + * Returns the maximum value (inclusive). * @return the maxvalue */ public synchronized String getMaximumValue() { @@ -163,6 +166,7 @@ public synchronized String getMaximumValue() { } /** + * Configures the maximum value (inclusive). * @param maxvalue the maxvalue to set */ public synchronized void setMaximumValue(String maxvalue) { @@ -170,6 +174,7 @@ public synchronized void setMaximumValue(String maxvalue) { } /** + * Returns the variable name. * @return the variableName */ public synchronized String getVariableName() { @@ -177,6 +182,7 @@ public synchronized String getVariableName() { } /** + * Configures the variable name. * @param variableName the variableName to set */ public synchronized void setVariableName(String variableName) { @@ -184,6 +190,7 @@ public synchronized void setVariableName(String variableName) { } /** + * Returns the random seed. * @return the randomSeed */ public synchronized String getRandomSeed() { @@ -201,6 +208,7 @@ private Random createRandom() { } /** + * Returns the random seed as long. * @return the randomSeed as a long */ private synchronized Long getRandomSeedAsLong() { @@ -216,6 +224,7 @@ private synchronized Long getRandomSeedAsLong() { } /** + * Configures the random seed. * @param randomSeed the randomSeed to set */ public synchronized void setRandomSeed(String randomSeed) { @@ -223,6 +232,7 @@ public synchronized void setRandomSeed(String randomSeed) { } /** + * Returns {@code true} if the random is computed per thread. * @return the perThread */ public synchronized boolean getPerThread() { @@ -230,18 +240,21 @@ public synchronized boolean getPerThread() { } /** + * Configures if the random is computed per thread. * @param perThread the perThread to set */ public synchronized void setPerThread(boolean perThread) { this.perThread = perThread; } /** + * Returns the output format. * @return the outputFormat */ public synchronized String getOutputFormat() { return outputFormat; } /** + * Configures the output format. * @param outputFormat the outputFormat to set */ public synchronized void setOutputFormat(String outputFormat) { diff --git a/src/components/src/main/java/org/apache/jmeter/modifiers/CounterConfig.java b/src/components/src/main/java/org/apache/jmeter/modifiers/CounterConfig.java index 1280c9b7807..9eda96dae9b 100644 --- a/src/components/src/main/java/org/apache/jmeter/modifiers/CounterConfig.java +++ b/src/components/src/main/java/org/apache/jmeter/modifiers/CounterConfig.java @@ -159,6 +159,7 @@ public void setEnd(String end) { } /** + * Configures if the counter must be reset on Thread Group Iteration. * @param value boolean indicating if counter must be reset on Thread Group Iteration */ public void setResetOnThreadGroupIteration(boolean value) { @@ -166,6 +167,7 @@ public void setResetOnThreadGroupIteration(boolean value) { } /** + * Returns true if counter must be reset on Thread Group Iteration. * @return true if counter must be reset on Thread Group Iteration */ public boolean isResetOnThreadGroupIteration() { @@ -173,7 +175,7 @@ public boolean isResetOnThreadGroupIteration() { } /** - * + * Returns counter upper limit (default {@code Long.MAX_VALUE}). * @return counter upper limit (default Long.MAX_VALUE) */ public long getEnd() { diff --git a/src/launcher/src/main/java/org/apache/jmeter/DynamicClassLoader.java b/src/launcher/src/main/java/org/apache/jmeter/DynamicClassLoader.java index 65346e3d4c6..3a4a9931466 100644 --- a/src/launcher/src/main/java/org/apache/jmeter/DynamicClassLoader.java +++ b/src/launcher/src/main/java/org/apache/jmeter/DynamicClassLoader.java @@ -52,7 +52,7 @@ public void addURL(URL url) { } /** - * + * Returns list of URLs to add to the thread's classloader. * @param urls - list of URLs to add to the thread's classloader */ public static void updateLoader(URL [] urls) { diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSamplerContext.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSamplerContext.java index 0b854f1cf22..1fabe5e1707 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSamplerContext.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSamplerContext.java @@ -228,21 +228,23 @@ public long getLongParameter(String name, long defaultValue) { } /** - * - * @return {@link JMeterContext} + * Returns {@link JMeterContext} for the current thread. + * @return {@link JMeterContext} for the current thread */ public JMeterContext getJMeterContext() { return JMeterContextService.getContext(); } + /** - * @return {@link JMeterVariables} + * Returns {@link JMeterVariables} for the current thread. + * @return {@link JMeterVariables} for the current thread. */ public final JMeterVariables getJMeterVariables() { return JMeterContextService.getContext().getVariables(); } /** - * + * Returns JMeter properties. * @return {@link Properties} JMeter properties */ public final Properties getJMeterProperties() { From f5e3d7a633c6e4de5f4ac08a95cd20ed6ff37c8d Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:24:16 +0300 Subject: [PATCH 05/40] Suppress error-prone errors for junit-sample JUnitAmbiguousTestClass is intentional there --- .../junit-sample/src/main/java/test/DummyAnnotatedTest.java | 2 ++ src/protocol/junit-sample/src/main/java/test/RerunTest.java | 1 + .../junit-sample/src/main/java/test/SetupTestError.java | 1 + src/protocol/junit-sample/src/main/java/test/SetupTestFail.java | 1 + .../junit-sample/src/main/java/woolfel/DummyTestCase.java | 1 + 5 files changed, 6 insertions(+) diff --git a/src/protocol/junit-sample/src/main/java/test/DummyAnnotatedTest.java b/src/protocol/junit-sample/src/main/java/test/DummyAnnotatedTest.java index 8c89917535d..e93749b69c2 100644 --- a/src/protocol/junit-sample/src/main/java/test/DummyAnnotatedTest.java +++ b/src/protocol/junit-sample/src/main/java/test/DummyAnnotatedTest.java @@ -60,6 +60,7 @@ public void printDone() { @Test // Succeeds only if Before method - verifyTwo() - is run. + @SuppressWarnings("UseCorrectAssertInTests") public void add() { int four = two + 2; if (4 != four) { @@ -94,6 +95,7 @@ public void alwaysFail() { @Test // Generate a test error + @SuppressWarnings("ConstantOverflow") public void divideByZero() { @SuppressWarnings("unused") int i = 27 / 0; // will generate Divide by zero error diff --git a/src/protocol/junit-sample/src/main/java/test/RerunTest.java b/src/protocol/junit-sample/src/main/java/test/RerunTest.java index f2155918455..692e187483f 100644 --- a/src/protocol/junit-sample/src/main/java/test/RerunTest.java +++ b/src/protocol/junit-sample/src/main/java/test/RerunTest.java @@ -24,6 +24,7 @@ /** * Test to demonstrate whether a test instance can be re-run */ +@SuppressWarnings("JUnitAmbiguousTestClass") public class RerunTest extends TestCase { private int i = 123; diff --git a/src/protocol/junit-sample/src/main/java/test/SetupTestError.java b/src/protocol/junit-sample/src/main/java/test/SetupTestError.java index 5b7eb95ceb6..7a8aedd81f3 100644 --- a/src/protocol/junit-sample/src/main/java/test/SetupTestError.java +++ b/src/protocol/junit-sample/src/main/java/test/SetupTestError.java @@ -25,6 +25,7 @@ /** * Test to demonstrate how setUp errors are handled */ +@SuppressWarnings("JUnitAmbiguousTestClass") public class SetupTestError extends TestCase { @Override diff --git a/src/protocol/junit-sample/src/main/java/test/SetupTestFail.java b/src/protocol/junit-sample/src/main/java/test/SetupTestFail.java index 9071dc937d4..2cf7930783c 100644 --- a/src/protocol/junit-sample/src/main/java/test/SetupTestFail.java +++ b/src/protocol/junit-sample/src/main/java/test/SetupTestFail.java @@ -25,6 +25,7 @@ /** * Test to demonstrate how setUp failures are handled */ +@SuppressWarnings("JUnitAmbiguousTestClass") public class SetupTestFail extends TestCase { @Override diff --git a/src/protocol/junit-sample/src/main/java/woolfel/DummyTestCase.java b/src/protocol/junit-sample/src/main/java/woolfel/DummyTestCase.java index 5ddd1c11e25..648f839c886 100644 --- a/src/protocol/junit-sample/src/main/java/woolfel/DummyTestCase.java +++ b/src/protocol/junit-sample/src/main/java/woolfel/DummyTestCase.java @@ -88,6 +88,7 @@ public void testFail() { } // Generate test error + @SuppressWarnings("ConstantOverflow") public void testException() { @SuppressWarnings("unused") int i = 27 / 0; // will generate Divide by zero error From ba94b52346b2bc694eafa300761c2d13cab35f80 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:25:27 +0300 Subject: [PATCH 06/40] Replace obsolete Vector and Hashtable with ArrayList and HashMap --- .../apache/jmeter/gui/SimpleCompoundEdit.java | 2 ++ .../property/CollectionProperty.java | 2 ++ .../org/apache/jmeter/util/JMeterUtils.java | 12 +++---- .../commons/cli/avalon/CLArgsParser.java | 33 ++++++++++--------- .../main/java/org/apache/log/ContextMap.java | 2 +- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/gui/SimpleCompoundEdit.java b/src/core/src/main/java/org/apache/jmeter/gui/SimpleCompoundEdit.java index 6f2355d678d..0939d05a844 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/SimpleCompoundEdit.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/SimpleCompoundEdit.java @@ -26,6 +26,7 @@ public class SimpleCompoundEdit extends CompoundEdit { /** * @return boolean true if edits is empty */ + @SuppressWarnings("JdkObsolete") public boolean isEmpty() { return edits.isEmpty(); } @@ -33,6 +34,7 @@ public boolean isEmpty() { /** * @return size of edits */ + @SuppressWarnings("JdkObsolete") public int size() { return edits.size(); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/CollectionProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/CollectionProperty.java index 53673cef070..174e430fa14 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/CollectionProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/CollectionProperty.java @@ -42,8 +42,10 @@ public CollectionProperty() { } @Override + @SuppressWarnings("UndefinedEquals") public boolean equals(Object o) { if (o instanceof CollectionProperty && value != null) { + // TODO: Collection does not have well-defined equals behavior return value.equals(((JMeterProperty) o).getObjectValue()); } return false; diff --git a/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java b/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java index f9de829a0e8..c2123a18141 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java @@ -39,7 +39,7 @@ import java.util.MissingResourceException; import java.util.Properties; import java.util.ResourceBundle; -import java.util.Vector; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; @@ -101,7 +101,8 @@ private LazyPatternCacheHolder() { private static volatile Properties appProperties; - private static final Vector localeChangeListeners = new Vector<>(); + private static final CopyOnWriteArrayList localeChangeListeners = + new CopyOnWriteArrayList<>(); private static volatile Locale locale; @@ -414,12 +415,7 @@ public static void removeLocaleChangeListener(LocaleChangeListener listener) { */ private static void notifyLocaleChangeListeners() { LocaleChangeEvent event = new LocaleChangeEvent(JMeterUtils.class, locale); - @SuppressWarnings("unchecked") // clone will produce correct type - // TODO but why do we need to clone the list? - // ANS: to avoid possible ConcurrentUpdateException when unsubscribing - // Could perhaps avoid need to clone by using a modern concurrent list - Vector listeners = (Vector) localeChangeListeners.clone(); - for (LocaleChangeListener listener : listeners) { + for (LocaleChangeListener listener : localeChangeListeners) { listener.localeChanged(event); } } diff --git a/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLArgsParser.java b/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLArgsParser.java index 08db7e2ffa9..b49b56f053e 100644 --- a/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLArgsParser.java +++ b/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLArgsParser.java @@ -18,8 +18,10 @@ package org.apache.commons.cli.avalon; import java.text.ParseException; -import java.util.Hashtable; -import java.util.Vector; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Parser for command line arguments. @@ -62,10 +64,10 @@ public final class CLArgsParser { private final CLOptionDescriptor[] optionDescriptors; - private final Vector options; + private final List options = new ArrayList<>(); // Key is String or Integer - private Hashtable optionIndex; + private Map optionIndex; private final ParserControl control; @@ -109,7 +111,7 @@ public final String[] getUnparsedArgs() { * * @return the list of options */ - public final Vector getArguments() { + public final List getArguments() { return this.options; } @@ -218,7 +220,6 @@ private int getStateFor(final CLOptionDescriptor descriptor) { public CLArgsParser(final String[] args, final CLOptionDescriptor[] optionDescriptors, final ParserControl control) { this.optionDescriptors = optionDescriptors; this.control = control; - this.options = new Vector<>(); this.args = args; try { @@ -237,11 +238,11 @@ public CLArgsParser(final String[] args, final CLOptionDescriptor[] optionDescri * @param arguments * the arguments */ - private void checkIncompatibilities(final Vector arguments) throws ParseException { + private void checkIncompatibilities(final List arguments) throws ParseException { final int size = arguments.size(); for (int i = 0; i < size; i++) { - final CLOption option = arguments.elementAt(i); + final CLOption option = arguments.get(i); final int id = option.getDescriptor().getId(); final CLOptionDescriptor descriptor = getDescriptorFor(id); @@ -257,7 +258,7 @@ private void checkIncompatibilities(final Vector arguments) throws Par } } - private void checkIncompatible(final Vector arguments, final int[] incompatible, final int original) + private void checkIncompatible(final List arguments, final int[] incompatible, final int original) throws ParseException { final int size = arguments.size(); @@ -266,12 +267,12 @@ private void checkIncompatible(final Vector arguments, final int[] inc continue; } - final CLOption option = arguments.elementAt(i); + final CLOption option = arguments.get(i); final int id = option.getDescriptor().getId(); for (int anIncompatible : incompatible) { if (id == anIncompatible) { - final CLOption originalOption = arguments.elementAt(original); + final CLOption originalOption = arguments.get(original); final int originalId = originalOption.getDescriptor().getId(); String message = null; @@ -398,7 +399,7 @@ private void parse() throws ParseException { // Reached end of input arguments - perform final processing if (this.option != null) { if (STATE_OPTIONAL_ARG == this.state) { - this.options.addElement(this.option); + this.options.add(this.option); } else if (STATE_REQUIRE_ARG == this.state) { final CLOptionDescriptor descriptor = getDescriptorFor(this.option.getDescriptor().getId()); final String message = "Missing argument to option " + getOptionDescription(descriptor); @@ -406,7 +407,7 @@ private void parse() throws ParseException { } else if (STATE_REQUIRE_2ARGS == this.state) { if (1 == this.option.getArgumentCount()) { this.option.addArgument(""); - this.options.addElement(this.option); + this.options.add(this.option); } else { final CLOptionDescriptor descriptor = getDescriptorFor(this.option.getDescriptor().getId()); final String message = "Missing argument to option " + getOptionDescription(descriptor); @@ -497,7 +498,7 @@ private boolean isSeparator(final char ch, final char[] separators) { } private void addOption(final CLOption option) { - this.options.addElement(option); + this.options.add(option); this.lastOptionId = option.getDescriptor().getId(); this.option = null; } @@ -588,7 +589,7 @@ private void parseArguments() throws ParseException { if (0 == this.ch && '-' == peekAtChar()) { // Yes, so the second argument is missing this.option.addArgument(""); - this.options.addElement(this.option); + this.options.add(this.option); this.state = STATE_NORMAL; } } else // 2nd argument @@ -656,7 +657,7 @@ private void parseNormal() throws ParseException { */ private void buildOptionIndex() { final int size = this.options.size(); - this.optionIndex = new Hashtable<>(size * 2); + this.optionIndex = new HashMap<>(size * 2); for (final CLOption option : this.options) { final CLOptionDescriptor optionDescriptor = getDescriptorFor(option.getDescriptor().getId()); diff --git a/src/jorphan/src/main/java/org/apache/log/ContextMap.java b/src/jorphan/src/main/java/org/apache/log/ContextMap.java index a96c5a5d947..0996ec22c1d 100644 --- a/src/jorphan/src/main/java/org/apache/log/ContextMap.java +++ b/src/jorphan/src/main/java/org/apache/log/ContextMap.java @@ -41,7 +41,7 @@ * @deprecated Will be dropped in 3.3 */ @Deprecated -@SuppressWarnings({"unchecked","rawtypes"}) // will be dropped in 3.3 +@SuppressWarnings({"unchecked", "rawtypes", "JdkObsolete"}) // will be dropped in 3.3 public final class ContextMap implements Serializable { From b3b2eecc396d1fc38a4c4d1cf89e3c7ade1d95d7 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:26:15 +0300 Subject: [PATCH 07/40] Replace LinkedList with ArrayList --- .../jmeter/assertions/CompareAssertion.java | 4 +- .../jmeter/control/IncludeController.java | 6 +-- .../jmeter/modifiers/UserParameters.java | 4 +- .../jmeter/visualizers/RenderAsRegexp.java | 4 +- .../jmeter/visualizers/RequestPanel.java | 7 ++-- .../graphite/PickleGraphiteMetricsSender.java | 6 +-- .../main/java/org/apache/jmeter/JMeter.java | 9 ++--- .../jmeter/control/GenericController.java | 7 ++-- .../jmeter/engine/DistributedRunner.java | 7 ++-- .../jmeter/engine/StandardJMeterEngine.java | 3 +- .../org/apache/jmeter/engine/TreeCloner.java | 9 +++-- .../jmeter/engine/util/CompoundVariable.java | 9 +++-- .../jmeter/engine/util/FunctionParser.java | 12 +++--- .../jmeter/engine/util/ValueReplacer.java | 4 +- .../jmeter/gui/action/LoadRecentProject.java | 23 ++++++++---- .../apache/jmeter/gui/action/RemoteStart.java | 4 +- .../org/apache/jmeter/gui/action/Save.java | 3 +- .../org/apache/jmeter/gui/action/Start.java | 4 +- .../jmeter/gui/tree/JMeterTreeModel.java | 4 +- .../apache/jmeter/gui/util/FileListPanel.java | 4 +- .../jmeter/gui/util/FilePanelEntry.java | 4 +- .../jmeter/gui/util/JLabeledRadioI18N.java | 3 +- .../apache/jmeter/gui/util/JMeterMenuBar.java | 11 +++--- .../apache/jmeter/gui/util/MenuFactory.java | 24 ++++++------ .../processor/ExternalSampleSorter.java | 9 ++--- .../processor/graph/IndexedNameSelector.java | 6 +-- .../org/apache/jmeter/samplers/Entry.java | 4 +- .../jmeter/testbeans/TestBeanHelper.java | 4 +- .../jmeter/testbeans/gui/TableEditor.java | 4 +- .../jmeter/testbeans/gui/TestBeanGUI.java | 3 +- .../apache/jmeter/testelement/TestPlan.java | 6 +-- .../FindTestElementsUpToRootTraverser.java | 7 ++-- .../apache/jmeter/threads/TestCompiler.java | 37 ++++++++++--------- .../jmeter/functions/AbstractHostIPName.java | 4 +- .../apache/jmeter/functions/BeanShell.java | 4 +- .../org/apache/jmeter/functions/CSVRead.java | 4 +- .../apache/jmeter/functions/ChangeCase.java | 4 +- .../apache/jmeter/functions/CharFunction.java | 4 +- .../functions/DateTimeConvertFunction.java | 4 +- .../functions/DigestEncodeFunction.java | 4 +- .../apache/jmeter/functions/EscapeHtml.java | 4 +- .../functions/EscapeOroRegexpChars.java | 4 +- .../apache/jmeter/functions/EscapeXml.java | 4 +- .../apache/jmeter/functions/EvalFunction.java | 4 +- .../jmeter/functions/EvalVarFunction.java | 4 +- .../apache/jmeter/functions/FileToString.java | 4 +- .../org/apache/jmeter/functions/Groovy.java | 4 +- .../org/apache/jmeter/functions/IntSum.java | 4 +- .../jmeter/functions/IsPropDefined.java | 4 +- .../apache/jmeter/functions/IsVarDefined.java | 4 +- .../jmeter/functions/IterationCounter.java | 4 +- .../apache/jmeter/functions/JavaScript.java | 4 +- .../jmeter/functions/Jexl2Function.java | 4 +- .../jmeter/functions/Jexl3Function.java | 4 +- .../apache/jmeter/functions/LogFunction.java | 4 +- .../apache/jmeter/functions/LogFunction2.java | 4 +- .../org/apache/jmeter/functions/LongSum.java | 4 +- .../org/apache/jmeter/functions/Property.java | 4 +- .../apache/jmeter/functions/Property2.java | 4 +- .../org/apache/jmeter/functions/Random.java | 4 +- .../functions/RandomFromMultipleVars.java | 3 +- .../apache/jmeter/functions/RandomString.java | 4 +- .../jmeter/functions/RegexFunction.java | 5 +-- .../apache/jmeter/functions/SamplerName.java | 4 +- .../apache/jmeter/functions/SetProperty.java | 4 +- .../jmeter/functions/SplitFunction.java | 4 +- .../jmeter/functions/StringFromFile.java | 4 +- .../apache/jmeter/functions/StringToFile.java | 4 +- .../apache/jmeter/functions/TestPlanName.java | 4 +- .../jmeter/functions/ThreadGroupName.java | 4 +- .../apache/jmeter/functions/ThreadNumber.java | 4 +- .../apache/jmeter/functions/TimeFunction.java | 4 +- .../org/apache/jmeter/functions/UnEscape.java | 4 +- .../apache/jmeter/functions/UnEscapeHtml.java | 4 +- .../apache/jmeter/functions/UrlDecode.java | 4 +- .../apache/jmeter/functions/UrlEncode.java | 4 +- .../org/apache/jmeter/functions/Uuid.java | 4 +- .../org/apache/jmeter/functions/Variable.java | 4 +- .../org/apache/jmeter/functions/XPath.java | 4 +- .../jorphan/collections/ListedHashTree.java | 4 +- .../jorphan/collections/SearchByClass.java | 4 +- .../apache/jorphan/gui/JLabeledChoice.java | 3 +- .../apache/jorphan/gui/JLabeledTextArea.java | 3 +- .../apache/jorphan/gui/JLabeledTextField.java | 3 +- .../java/org/apache/jmeter/NewDriver.java | 5 ++- .../http/modifier/AnchorModifier.java | 3 +- .../protocol/http/proxy/ProxyControl.java | 13 ++++++- .../http/proxy/gui/ProxyControlGui.java | 9 ++--- .../protocol/http/util/HTTPArgument.java | 4 +- 89 files changed, 249 insertions(+), 241 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java b/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java index 508b24f288c..96d78ba6083 100644 --- a/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java +++ b/src/components/src/main/java/org/apache/jmeter/assertions/CompareAssertion.java @@ -18,8 +18,8 @@ package org.apache.jmeter.assertions; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.event.LoopIterationEvent; @@ -170,7 +170,7 @@ private String filterString(final String content) { @Override public void iterationStart(LoopIterationEvent iterEvent) { - responses = new LinkedList<>(); + responses = new ArrayList<>(); } /** diff --git a/src/components/src/main/java/org/apache/jmeter/control/IncludeController.java b/src/components/src/main/java/org/apache/jmeter/control/IncludeController.java index cde625680ee..2fd00cc725a 100644 --- a/src/components/src/main/java/org/apache/jmeter/control/IncludeController.java +++ b/src/components/src/main/java/org/apache/jmeter/control/IncludeController.java @@ -20,7 +20,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.util.LinkedList; +import java.util.ArrayList; import org.apache.jmeter.gui.tree.JMeterTreeNode; import org.apache.jmeter.save.SaveService; @@ -173,7 +173,7 @@ protected HashTree loadIncludedElements() { * @return HashTree Subset within Test Fragment or Empty HashTree */ private HashTree getProperBranch(HashTree tree) { - for (Object o : new LinkedList<>(tree.list())) { + for (Object o : new ArrayList<>(tree.list())) { TestElement item = (TestElement) o; //if we found a TestPlan, then we are on our way to the TestFragment @@ -193,7 +193,7 @@ private HashTree getProperBranch(HashTree tree) { private void removeDisabledItems(HashTree tree) { - for (Object o : new LinkedList<>(tree.list())) { + for (Object o : new ArrayList<>(tree.list())) { TestElement item = (TestElement) o; if (!item.isEnabled()) { tree.remove(item); diff --git a/src/components/src/main/java/org/apache/jmeter/modifiers/UserParameters.java b/src/components/src/main/java/org/apache/jmeter/modifiers/UserParameters.java index dd2d76f5639..2bbfcdbc98f 100644 --- a/src/components/src/main/java/org/apache/jmeter/modifiers/UserParameters.java +++ b/src/components/src/main/java/org/apache/jmeter/modifiers/UserParameters.java @@ -18,8 +18,8 @@ package org.apache.jmeter.modifiers; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.engine.event.LoopIterationListener; @@ -121,7 +121,7 @@ private CollectionProperty getValues() { if (threadValues.size() > 0) { return (CollectionProperty) threadValues.get(getThreadContext().getThreadNum() % threadValues.size()); } - return new CollectionProperty("noname", new LinkedList<>()); + return new CollectionProperty("noname", new ArrayList<>()); } public boolean isPerIteration() { diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsRegexp.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsRegexp.java index eaeb9db2891..66d74fb0021 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsRegexp.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsRegexp.java @@ -22,7 +22,7 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; @@ -119,7 +119,7 @@ private String process(String textToParse) { } catch (MalformedCachePatternException e) { return e.toString(); } - List matches = new LinkedList<>(); + List matches = new ArrayList<>(); while (matcher.contains(input, pattern)) { matches.add(matcher.getMatch()); } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java index a47b32fa7af..0c810554e12 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java @@ -19,8 +19,9 @@ import java.awt.BorderLayout; import java.io.IOException; +import java.util.ArrayDeque; import java.util.Collections; -import java.util.LinkedList; +import java.util.Deque; import java.util.List; import javax.swing.JPanel; @@ -41,7 +42,7 @@ public class RequestPanel { private static final Logger log = LoggerFactory.getLogger(RequestPanel.class); - private final LinkedList listRequestView; + private final Deque listRequestView; private final JPanel panel; @@ -50,7 +51,7 @@ public class RequestPanel { * and Create Request Panel */ public RequestPanel() { - listRequestView = new LinkedList<>(); + listRequestView = new ArrayDeque<>(); List classesToAdd = Collections. emptyList(); try { classesToAdd = JMeterUtils.findClassesThatExtend(RequestView.class); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/PickleGraphiteMetricsSender.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/PickleGraphiteMetricsSender.java index 16be98b460c..bd33c81c755 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/PickleGraphiteMetricsSender.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/graphite/PickleGraphiteMetricsSender.java @@ -20,7 +20,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.ByteBuffer; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; @@ -52,7 +52,7 @@ class PickleGraphiteMetricsSender extends AbstractGraphiteMetricsSender { private final Object lock = new Object(); // graphite expects a python-pickled list of nested tuples. - private List metrics = new LinkedList<>(); + private List metrics = new ArrayList<>(); private SocketConnectionInfos socketConnectionInfos; private GenericKeyedObjectPool socketOutputStreamPool; @@ -118,7 +118,7 @@ public void writeAndSendMetrics() { } // keep the current metrics to send outside sync block currentMetrics = metrics; - metrics = new LinkedList<>(); + metrics = new ArrayList<>(); } writeMetrics(currentMetrics); } diff --git a/src/core/src/main/java/org/apache/jmeter/JMeter.java b/src/core/src/main/java/org/apache/jmeter/JMeter.java index f3e93a2fbe6..3feca429d2d 100644 --- a/src/core/src/main/java/org/apache/jmeter/JMeter.java +++ b/src/core/src/main/java/org/apache/jmeter/JMeter.java @@ -32,11 +32,11 @@ import java.net.SocketException; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Enumeration; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -1078,7 +1078,7 @@ void runNonGui(String testFile, String logFile, boolean remoteStart, String remo // when NON GUI mode is used clonedTree.add(clonedTree.getArray()[0], new RemoteThreadsListenerTestElement()); - List engines = new LinkedList<>(); + List engines = new ArrayList<>(); println("Created the tree successfully using "+testFile); if (!remoteStart) { JMeterEngine engine = new StandardJMeterEngine(); @@ -1091,7 +1091,7 @@ void runNonGui(String testFile, String logFile, boolean remoteStart, String remo engine.runTest(); } else { java.util.StringTokenizer st = new java.util.StringTokenizer(remoteHostsString.trim(), ",");//$NON-NLS-1$ - List hosts = new LinkedList<>(); + List hosts = new ArrayList<>(); while (st.hasMoreElements()) { hosts.add(((String) st.nextElement()).trim()); } @@ -1164,8 +1164,7 @@ public static HashTree convertSubTree(HashTree tree, boolean cloneAtEnd) { * @param tree The {@link HashTree} to convert */ private static void pConvertSubTree(HashTree tree) { - LinkedList copyList = new LinkedList<>(tree.list()); - for (Object o : copyList) { + for (Object o : new ArrayList<>(tree.list())) { if (o instanceof TestElement) { TestElement item = (TestElement) o; if (item.isEnabled()) { diff --git a/src/core/src/main/java/org/apache/jmeter/control/GenericController.java b/src/core/src/main/java/org/apache/jmeter/control/GenericController.java index f6275bf1c60..4d9d721395d 100644 --- a/src/core/src/main/java/org/apache/jmeter/control/GenericController.java +++ b/src/core/src/main/java/org/apache/jmeter/control/GenericController.java @@ -18,9 +18,10 @@ package org.apache.jmeter.control; import java.io.Serializable; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -54,7 +55,7 @@ public class GenericController extends AbstractTestElement implements Controller static final String INDEX_VAR_NAME_SUFFIX = "__idx"; - private transient LinkedList iterationListeners = new LinkedList<>(); + private transient Deque iterationListeners = new ArrayDeque<>(); // Only create the map if it is required private transient ConcurrentMap children = new ConcurrentHashMap<>(); @@ -412,7 +413,7 @@ protected void resetIterCount() { } protected Object readResolve(){ - iterationListeners = new LinkedList<>(); + iterationListeners = new ArrayDeque<>(); children = new ConcurrentHashMap<>(); subControllersAndSamplers = new ArrayList<>(); diff --git a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java index bd5a268f092..b924799decc 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java @@ -26,7 +26,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -74,7 +73,7 @@ public DistributedRunner(Properties props) { public void init(List addresses, HashTree tree) { // converting list into mutable version - List addrs = new LinkedList<>(addresses); + List addrs = new ArrayList<>(addresses); for (int tryNo = 0; tryNo < retriesNumber; tryNo++) { if (tryNo > 0) { @@ -152,7 +151,7 @@ public void start(List addresses) { * Start all engines that were previously initiated */ public void start() { - List addresses = new LinkedList<>(engines.keySet()); + List addresses = new ArrayList<>(engines.keySet()); start(addresses); } @@ -177,7 +176,7 @@ public void stop(List addresses) { * Stop all engines that were previously initiated */ public void stop() { - List addresses = new LinkedList<>(engines.keySet()); + List addresses = new ArrayList<>(engines.keySet()); stop(addresses); } diff --git a/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java b/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java index 62ed775ab98..d4df3ef668e 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Properties; import java.util.concurrent.CopyOnWriteArrayList; @@ -380,7 +379,7 @@ public void run() { test.traverse(new TurnElementsOn()); notifyTestListenersOfStart(testListeners); - List testLevelElements = new LinkedList<>(test.list(test.getArray()[0])); + List testLevelElements = new ArrayList<>(test.list(test.getArray()[0])); removeThreadGroups(testLevelElements); SearchByClass setupSearcher = new SearchByClass<>(SetupThreadGroup.class); diff --git a/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java b/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java index 95793f61503..19b236b514d 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java @@ -17,7 +17,8 @@ package org.apache.jmeter.engine; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.List; import org.apache.jmeter.engine.util.NoThreadClone; import org.apache.jmeter.testelement.TestElement; @@ -32,7 +33,7 @@ public class TreeCloner implements HashTreeTraverser { private final ListedHashTree newTree; - private final LinkedList objects = new LinkedList<>(); + private final List objects = new ArrayList<>(); private final boolean honourNoThreadClone; @@ -86,12 +87,12 @@ protected Object addNodeToTree(Object node) { * @param node Object */ private void addLast(Object node) { - objects.addLast(node); + objects.add(node); } @Override public void subtractNode() { - objects.removeLast(); + objects.remove(objects.size() - 1); } public ListedHashTree getClonedTree() { diff --git a/src/core/src/main/java/org/apache/jmeter/engine/util/CompoundVariable.java b/src/core/src/main/java/org/apache/jmeter/engine/util/CompoundVariable.java index ca12a766ea5..7301afef279 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/util/CompoundVariable.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/util/CompoundVariable.java @@ -17,9 +17,9 @@ package org.apache.jmeter.engine.util; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -53,7 +53,8 @@ public class CompoundVariable implements Function { private String permanentResults; - private LinkedList compiledComponents = new LinkedList<>(); + // Type is ArrayList, so we can use ArrayList#clone + private ArrayList compiledComponents = new ArrayList<>(); static { try { @@ -152,7 +153,7 @@ public String execute(SampleResult previousResult, Sampler currentSampler) { @SuppressWarnings("unchecked") // clone will produce correct type public CompoundVariable getFunction() { CompoundVariable func = new CompoundVariable(); - func.compiledComponents = (LinkedList) compiledComponents.clone(); + func.compiledComponents = (ArrayList) compiledComponents.clone(); func.rawParameters = rawParameters; func.hasFunction = hasFunction; func.isDynamic = isDynamic; @@ -162,7 +163,7 @@ public CompoundVariable getFunction() { /** {@inheritDoc} */ @Override public List getArgumentDesc() { - return new LinkedList<>(); + return new ArrayList<>(); } public void clear() { diff --git a/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java b/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java index 8f5a16c2b4f..f1dff442f43 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/util/FunctionParser.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.io.StringReader; -import java.util.LinkedList; +import java.util.ArrayList; import org.apache.jmeter.engine.StandardJMeterEngine; import org.apache.jmeter.functions.Function; @@ -49,9 +49,9 @@ class FunctionParser { * @return list of Strings or Objects representing functions * @throws InvalidVariableException when evaluation of variables fail */ - LinkedList compileString(String value) throws InvalidVariableException { + ArrayList compileString(String value) throws InvalidVariableException { StringReader reader = new StringReader(value); - LinkedList result = new LinkedList<>(); + ArrayList result = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); char previous = ' '; // TODO - why use space? char[] current = new char[1]; @@ -145,7 +145,7 @@ Object makeFunction(StringReader reader) throws InvalidVariableException { } else if (current[0] == '}') {// variable, or function with no parameter list function = CompoundVariable.getNamedFunction(buffer.toString()); if (function instanceof Function){// ensure that setParameters() is called. - ((Function) function).setParameters(new LinkedList()); + ((Function) function).setParameters(new ArrayList<>()); } buffer.setLength(0); return function; @@ -186,8 +186,8 @@ private char firstNonSpace(StringReader reader, char defaultResult) throws IOExc * @return a list of CompoundVariable elements * @throws InvalidVariableException when evaluation of variables fail */ - LinkedList parseParams(StringReader reader) throws InvalidVariableException { - LinkedList result = new LinkedList<>(); + ArrayList parseParams(StringReader reader) throws InvalidVariableException { + ArrayList result = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); char[] current = new char[1]; char previous = ' '; diff --git a/src/core/src/main/java/org/apache/jmeter/engine/util/ValueReplacer.java b/src/core/src/main/java/org/apache/jmeter/engine/util/ValueReplacer.java index a5a2c7d9d78..12d51d795f0 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/util/ValueReplacer.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/util/ValueReplacer.java @@ -17,9 +17,9 @@ package org.apache.jmeter.engine.util; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -156,7 +156,7 @@ public void addVariables(Map vars) { * @throws InvalidVariableException when transform throws an {@link InvalidVariableException} while transforming a value */ private Collection replaceValues(PropertyIterator iter, ValueTransformer transform) throws InvalidVariableException { - List props = new LinkedList<>(); + List props = new ArrayList<>(); while (iter.hasNext()) { JMeterProperty val = iter.next(); if (log.isDebugEnabled()) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java b/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java index c1e11240fa6..28ff6fe7992 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/LoadRecentProject.java @@ -20,8 +20,10 @@ import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.File; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.prefs.Preferences; @@ -81,7 +83,7 @@ private File getRecentFile(ActionEvent e) { * @return a List of JMenuItem, representing recent files. JMenuItem may not be visible */ public static List getRecentFileMenuItems() { - LinkedList menuItems = new LinkedList<>(); + List menuItems = new ArrayList<>(); // Get the preference for the recent files for(int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { // Create the menu item @@ -114,7 +116,7 @@ public static List getRecentFileMenuItems() { public static void updateRecentFileMenuItems(List menuItems, String loadedFileName) { // Get the preference for the recent files - LinkedList newRecentFiles = new LinkedList<>(); + Deque newRecentFiles = new ArrayDeque<>(); // Check if the new file is already in the recent list boolean alreadyExists = false; for(int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { @@ -127,16 +129,21 @@ public static void updateRecentFileMenuItems(List menuItems, String } } // Add the new file at the start of the list - newRecentFiles.add(0, loadedFileName); + newRecentFiles.addFirst(loadedFileName); // Remove the last item from the list if it was a brand new file if(!alreadyExists) { newRecentFiles.removeLast(); } // Store the recent files - for(int i = 0; i < NUMBER_OF_MENU_ITEMS; i++) { - String fileName = newRecentFiles.get(i); - if(fileName != null) { - setRecentFile(i, fileName); + int index = 0; + for (String fileName : newRecentFiles) { + if (fileName == null) { + continue; + } + setRecentFile(index, fileName); + index++; + if (index >= NUMBER_OF_MENU_ITEMS) { + break; } } // Update menu items to reflect recent files diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/RemoteStart.java b/src/core/src/main/java/org/apache/jmeter/gui/action/RemoteStart.java index 71d2c979585..a29be2cf2f5 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/RemoteStart.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/RemoteStart.java @@ -19,9 +19,9 @@ import java.awt.Component; import java.awt.event.ActionEvent; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.StringTokenizer; @@ -100,7 +100,7 @@ public void doAction(ActionEvent e) { private List getRemoteHosts() { String remoteHostsString = JMeterUtils.getPropDefault(REMOTE_HOSTS, LOCAL_HOST); StringTokenizer st = new StringTokenizer(remoteHostsString, REMOTE_HOSTS_SEPARATOR); - List list = new LinkedList<>(); + List list = new ArrayList<>(); while (st.hasMoreElements()) { list.add((String) st.nextElement()); } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java b/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java index fcf0906b69d..bc8c69f6cac 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/Save.java @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.regex.Pattern; @@ -454,7 +453,7 @@ private static boolean checkAcceptableForTestFragment(JMeterTreeNode[] nodes) { // package protected to allow access from test code void convertSubTree(HashTree tree) { - for (Object o : new LinkedList<>(tree.list())) { + for (Object o : new ArrayList<>(tree.list())) { JMeterTreeNode item = (JMeterTreeNode) o; convertSubTree(tree.getTree(item)); TestElement testElement = item.getTestElement(); // requires JMeterTreeNode diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/Start.java b/src/core/src/main/java/org/apache/jmeter/gui/action/Start.java index a7b74b6e9f9..712bb965b24 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/Start.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/Start.java @@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -231,8 +230,7 @@ private static TreeCloner createTreeClonerForValidation(boolean honorThreadClone * @param threadGroupsToKeep Array of {@link AbstractThreadGroup} to keep */ private void keepOnlySelectedThreadGroupsInHashTree(HashTree testTree, AbstractThreadGroup[] threadGroupsToKeep) { - LinkedList copyList = new LinkedList<>(testTree.list()); - for (Object o : copyList) { + for (Object o : new ArrayList<>(testTree.list())) { TestElement item = (TestElement) o; if (o instanceof AbstractThreadGroup) { if (!isInThreadGroups(item, threadGroupsToKeep)) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java index a4709d006b0..a771bae0404 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java @@ -17,9 +17,9 @@ package org.apache.jmeter.gui.tree; +import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; -import java.util.LinkedList; import java.util.List; import javax.swing.tree.DefaultTreeModel; @@ -80,7 +80,7 @@ public JMeterTreeModel(Object o) { * @return a list of tree nodes of the given type, or an empty list */ public List getNodesOfType(Class type) { - List nodeList = new LinkedList<>(); + List nodeList = new ArrayList<>(); traverseAndFind(type, (JMeterTreeNode) this.getRoot(), nodeList); return nodeList; } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/FileListPanel.java b/src/core/src/main/java/org/apache/jmeter/gui/util/FileListPanel.java index 919f0ff0ee3..f52a5056ff8 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/FileListPanel.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/FileListPanel.java @@ -22,7 +22,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; @@ -61,7 +61,7 @@ public class FileListPanel extends JPanel implements ActionListener { private JButton delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$ - private List listeners = new LinkedList<>(); + private List listeners = new ArrayList<>(); private String title; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/FilePanelEntry.java b/src/core/src/main/java/org/apache/jmeter/gui/util/FilePanelEntry.java index 51db86736f1..842a9cb977f 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/FilePanelEntry.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/FilePanelEntry.java @@ -19,7 +19,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.swing.JButton; @@ -43,7 +43,7 @@ public class FilePanelEntry extends HorizontalPanel implements ActionListener { private static final String ACTION_BROWSE = "browse"; //$NON-NLS-1$ - private final List listeners = new LinkedList<>(); + private final List listeners = new ArrayList<>(); private final String[] filetypes; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java index 7ce3a0e3cec..36e29066160 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java @@ -21,7 +21,6 @@ import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Enumeration; -import java.util.LinkedList; import java.util.List; import javax.swing.AbstractButton; @@ -205,7 +204,7 @@ private void notifyChangeListeners() { */ @Override public List getComponentList() { - List comps = new LinkedList<>(); + List comps = new ArrayList<>(); comps.add(mLabel); Enumeration en = this.bGroup.getElements(); while (en.hasMoreElements()) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java index 99a7106f5d4..f05d2623b5c 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -104,12 +103,12 @@ public class JMeterMenuBar extends JMenuBar implements LocaleChangeListener { public JMeterMenuBar() { // List for recent files menu items - fileLoadRecentFiles = new LinkedList<>(); + fileLoadRecentFiles = new ArrayList<>(); // Lists for remote engines menu items - remoteEngineStart = new LinkedList<>(); - remoteEngineStop = new LinkedList<>(); - remoteEngineShut = new LinkedList<>(); - remoteEngineExit = new LinkedList<>(); + remoteEngineStart = new ArrayList<>(); + remoteEngineStop = new ArrayList<>(); + remoteEngineShut = new ArrayList<>(); + remoteEngineExit = new ArrayList<>(); remoteHosts = JOrphanUtils.split(JMeterUtils.getPropDefault("remote_hosts", ""), ","); //$NON-NLS-1$ if (remoteHosts.length == 1 && remoteHosts[0].isEmpty()) { remoteHosts = new String[0]; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/MenuFactory.java b/src/core/src/main/java/org/apache/jmeter/gui/util/MenuFactory.java index 939a7d77361..4aafa803415 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/MenuFactory.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/MenuFactory.java @@ -20,12 +20,12 @@ import java.awt.Component; import java.awt.HeadlessException; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -90,17 +90,17 @@ public final class MenuFactory { static { menuMap = new HashMap<>(); - menuMap.put(THREADS, new LinkedList<>()); - menuMap.put(TIMERS, new LinkedList<>()); - menuMap.put(ASSERTIONS, new LinkedList<>()); - menuMap.put(CONFIG_ELEMENTS, new LinkedList<>()); - menuMap.put(CONTROLLERS, new LinkedList<>()); - menuMap.put(LISTENERS, new LinkedList<>()); - menuMap.put(NON_TEST_ELEMENTS, new LinkedList<>()); - menuMap.put(SAMPLERS, new LinkedList<>()); - menuMap.put(POST_PROCESSORS, new LinkedList<>()); - menuMap.put(PRE_PROCESSORS, new LinkedList<>()); - menuMap.put(FRAGMENTS, new LinkedList<>()); + menuMap.put(THREADS, new ArrayList<>()); + menuMap.put(TIMERS, new ArrayList<>()); + menuMap.put(ASSERTIONS, new ArrayList<>()); + menuMap.put(CONFIG_ELEMENTS, new ArrayList<>()); + menuMap.put(CONTROLLERS, new ArrayList<>()); + menuMap.put(LISTENERS, new ArrayList<>()); + menuMap.put(NON_TEST_ELEMENTS, new ArrayList<>()); + menuMap.put(SAMPLERS, new ArrayList<>()); + menuMap.put(POST_PROCESSORS, new ArrayList<>()); + menuMap.put(PRE_PROCESSORS, new ArrayList<>()); + menuMap.put(FRAGMENTS, new ArrayList<>()); menuMap.put(SEPARATOR, Collections.singletonList(new MenuSeparatorInfo())); try { diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/ExternalSampleSorter.java b/src/core/src/main/java/org/apache/jmeter/report/processor/ExternalSampleSorter.java index bc21387fa24..bf3a9eeb2eb 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/ExternalSampleSorter.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/ExternalSampleSorter.java @@ -20,7 +20,6 @@ import java.io.File; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.concurrent.BlockingQueue; @@ -102,9 +101,9 @@ public class ExternalSampleSorter extends AbstractSampleConsumer { private final AtomicLong inputSampleCount = new AtomicLong(); - private LinkedList chunks; + private List chunks; - private LinkedList samples; + private List samples; private SampleMetadata sampleMetadata; @@ -281,8 +280,8 @@ public void startConsuming() { this.pool.prestartAllCoreThreads(); inputSampleCount.set(0); chunkedSampleCount.set(0); - chunks = new LinkedList<>(); - samples = new LinkedList<>(); + chunks = new ArrayList<>(); + samples = new ArrayList<>(); sampleMetadata = getConsumedMetadata(0); sampleComparator.initialize(sampleMetadata); } diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/IndexedNameSelector.java b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/IndexedNameSelector.java index 425a5473eb0..21a8bb27b82 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/IndexedNameSelector.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/IndexedNameSelector.java @@ -17,7 +17,7 @@ package org.apache.jmeter.report.processor.graph; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.jmeter.report.core.Sample; @@ -31,7 +31,7 @@ public class IndexedNameSelector implements GraphKeysSelector { /** The names. */ - private LinkedList names = new LinkedList<>(); + private final List names = new ArrayList<>(); /** * Gets the names. @@ -54,7 +54,7 @@ public Double select(Sample sample) { String name = sample.getName(); int index = names.indexOf(name); if (index < 0) { - names.addLast(name); + names.add(name); index = names.size() - 1; } return (double) index; diff --git a/src/core/src/main/java/org/apache/jmeter/samplers/Entry.java b/src/core/src/main/java/org/apache/jmeter/samplers/Entry.java index 7e1fbd16b64..67de578e4ec 100644 --- a/src/core/src/main/java/org/apache/jmeter/samplers/Entry.java +++ b/src/core/src/main/java/org/apache/jmeter/samplers/Entry.java @@ -17,8 +17,8 @@ package org.apache.jmeter.samplers; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -36,7 +36,7 @@ public class Entry { public Entry() { configSet = new HashMap<>(); - assertions = new LinkedList<>(); + assertions = new ArrayList<>(); } public void addAssertion(Assertion assertion) { diff --git a/src/core/src/main/java/org/apache/jmeter/testbeans/TestBeanHelper.java b/src/core/src/main/java/org/apache/jmeter/testbeans/TestBeanHelper.java index 5eaa40e07c4..fa19b19d8cb 100644 --- a/src/core/src/main/java/org/apache/jmeter/testbeans/TestBeanHelper.java +++ b/src/core/src/main/java/org/apache/jmeter/testbeans/TestBeanHelper.java @@ -23,8 +23,8 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer; import org.apache.jmeter.testbeans.gui.TableEditor; @@ -135,7 +135,7 @@ private static Object unwrapCollection(MultiProperty prop, String type) { if(prop instanceof CollectionProperty) { - Collection values = new LinkedList<>(); + Collection values = new ArrayList<>(); for (JMeterProperty jMeterProperty : prop) { try { values.add(unwrapProperty(null, jMeterProperty, Class.forName(type))); diff --git a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TableEditor.java b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TableEditor.java index e7448446934..ab6a8a45790 100644 --- a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TableEditor.java +++ b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TableEditor.java @@ -27,9 +27,9 @@ import java.beans.PropertyDescriptor; import java.beans.PropertyEditorSupport; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -177,7 +177,7 @@ public void setValue(Object value) { } private Collection convertCollection(Collection values) { - List l = new LinkedList<>(); + List l = new ArrayList<>(); for(Object obj : values) { if(obj instanceof TestElementProperty) { l.add(((TestElementProperty)obj).getElement()); diff --git a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TestBeanGUI.java b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TestBeanGUI.java index 6e0d8952ec1..f840335b2a2 100644 --- a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TestBeanGUI.java +++ b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/TestBeanGUI.java @@ -30,7 +30,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -125,7 +124,7 @@ public class TestBeanGUI extends AbstractJMeterGuiComponent implements JMeterGUI private List menuCategories; static { - List paths = new LinkedList<>(); + List paths = new ArrayList<>(); paths.add("org.apache.jmeter.testbeans.gui");// $NON-NLS-1$ paths.addAll(Arrays.asList(PropertyEditorManager.getEditorSearchPath())); String s = JMeterUtils.getPropDefault("propertyEditorSearchPath", null);// $NON-NLS-1$ diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/TestPlan.java b/src/core/src/main/java/org/apache/jmeter/testelement/TestPlan.java index e6dc735624e..4688a37e6ff 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/TestPlan.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/TestPlan.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.Serializable; import java.net.MalformedURLException; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,7 +57,7 @@ public class TestPlan extends AbstractTestElement implements Serializable, TestS private static final String BASEDIR = "basedir"; - private transient List threadGroups = new LinkedList<>(); + private transient List threadGroups = new ArrayList<>(); // There's only 1 test plan, so can cache the mode here private static volatile boolean functionalMode = false; @@ -72,7 +72,7 @@ public TestPlan(String name) { // create transient item protected Object readResolve(){ - threadGroups = new LinkedList<>(); + threadGroups = new ArrayList<>(); return this; } diff --git a/src/core/src/main/java/org/apache/jmeter/threads/FindTestElementsUpToRootTraverser.java b/src/core/src/main/java/org/apache/jmeter/threads/FindTestElementsUpToRootTraverser.java index 25e052d9881..6613e1b02c3 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/FindTestElementsUpToRootTraverser.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/FindTestElementsUpToRootTraverser.java @@ -17,8 +17,9 @@ package org.apache.jmeter.threads; +import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.LinkedList; +import java.util.Deque; import java.util.List; import org.apache.jmeter.control.Controller; @@ -35,7 +36,7 @@ public class FindTestElementsUpToRootTraverser implements HashTreeTraverser { private static final Logger log = LoggerFactory.getLogger(FindTestElementsUpToRootTraverser.class); - private final LinkedList stack = new LinkedList<>(); + private final Deque stack = new ArrayDeque<>(); /** * Node to find in TestTree @@ -89,7 +90,7 @@ public void processPath() { */ public List getControllersToRoot() { List result = new ArrayList<>(stack.size()); - LinkedList stackLocalCopy = new LinkedList<>(stack); + Deque stackLocalCopy = new ArrayDeque<>(stack); while(!stackLocalCopy.isEmpty()) { TestElement te = stackLocalCopy.getLast(); if(te instanceof Controller) { diff --git a/src/core/src/main/java/org/apache/jmeter/threads/TestCompiler.java b/src/core/src/main/java/org/apache/jmeter/threads/TestCompiler.java index cc5228e5491..2c0d4646528 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/TestCompiler.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/TestCompiler.java @@ -17,6 +17,7 @@ package org.apache.jmeter.threads; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -52,6 +53,7 @@ *
  • A map with key TransactionController and as value the associated SamplePackage
  • * */ +@SuppressWarnings("JdkObsolete") public class TestCompiler implements HashTreeTraverser { private static final Logger log = LoggerFactory.getLogger(TestCompiler.class); @@ -64,6 +66,7 @@ public class TestCompiler implements HashTreeTraverser { */ private static final Set PAIRING = new HashSet<>(); + // TODO: replace with ArrayDequeue private final LinkedList stack = new LinkedList<>(); private final Map samplerConfigMap = new HashMap<>(); @@ -193,18 +196,18 @@ public void processPath() { } private void saveSamplerConfigs(Sampler sam) { - List configs = new LinkedList<>(); - List controllers = new LinkedList<>(); - List listeners = new LinkedList<>(); - List timers = new LinkedList<>(); - List assertions = new LinkedList<>(); - LinkedList posts = new LinkedList<>(); - LinkedList pres = new LinkedList<>(); + List configs = new ArrayList<>(); + List controllers = new ArrayList<>(); + List listeners = new ArrayList<>(); + List timers = new ArrayList<>(); + List assertions = new ArrayList<>(); + List posts = new ArrayList<>(); + List pres = new ArrayList<>(); for (int i = stack.size(); i > 0; i--) { addDirectParentControllers(controllers, stack.get(i - 1)); - List tempPre = new LinkedList<>(); - List tempPost = new LinkedList<>(); - List tempAssertions = new LinkedList<>(); + List tempPre = new ArrayList<>(); + List tempPost = new ArrayList<>(); + List tempAssertions = new ArrayList<>(); for (Object item : testTree.list(stack.subList(0, i))) { if (item instanceof ConfigTestElement) { configs.add((ConfigTestElement) item); @@ -238,13 +241,13 @@ private void saveSamplerConfigs(Sampler sam) { } private void saveTransactionControllerConfigs(TransactionController tc) { - List configs = new LinkedList<>(); - List controllers = new LinkedList<>(); - List listeners = new LinkedList<>(); - List timers = new LinkedList<>(); - List assertions = new LinkedList<>(); - LinkedList posts = new LinkedList<>(); - LinkedList pres = new LinkedList<>(); + List configs = new ArrayList<>(); + List controllers = new ArrayList<>(); + List listeners = new ArrayList<>(); + List timers = new ArrayList<>(); + List assertions = new ArrayList<>(); + List posts = new ArrayList<>(); + List pres = new ArrayList<>(); for (int i = stack.size(); i > 0; i--) { addDirectParentControllers(controllers, stack.get(i - 1)); for (Object item : testTree.list(stack.subList(0, i))) { diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java index 6f85eb911ea..72836270b02 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -29,7 +29,7 @@ abstract class AbstractHostIPName extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); static { desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/BeanShell.java b/src/functions/src/main/java/org/apache/jmeter/functions/BeanShell.java index ce9cdca6f24..88d64cd8e6b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/BeanShell.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/BeanShell.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -40,7 +40,7 @@ public class BeanShell extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(BeanShell.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__BeanShell"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/CSVRead.java b/src/functions/src/main/java/org/apache/jmeter/functions/CSVRead.java index c49c7bfa5d6..c9a80a34a5b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/CSVRead.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/CSVRead.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -58,7 +58,7 @@ public class CSVRead extends AbstractFunction { private static final String KEY = "__CSVRead"; // Function name //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private Object[] values; // Parameter list diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java b/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java index fb06af97724..2a16a12d885 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java @@ -17,9 +17,9 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; -import java.util.LinkedList; import java.util.List; import org.apache.commons.lang3.StringUtils; @@ -46,7 +46,7 @@ */ public class ChangeCase extends AbstractFunction { private static final Logger LOGGER = LoggerFactory.getLogger(ChangeCase.class); - private static final List DESC = new LinkedList<>(); + private static final List DESC = new ArrayList<>(); private static final String KEY = "__changeCase"; private static final int MIN_PARAMETER_COUNT = 1; diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/CharFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/CharFunction.java index d474cdcf652..94e5df40c12 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/CharFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/CharFunction.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -36,7 +36,7 @@ public class CharFunction extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(CharFunction.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__char"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java index d0fd394d6d5..fb80f3a3cbf 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java @@ -18,9 +18,9 @@ package org.apache.jmeter.functions; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -40,7 +40,7 @@ public class DateTimeConvertFunction extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(DateTimeConvertFunction.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__dateTimeConvert"; // Number of parameters expected - used to reject invalid calls diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/DigestEncodeFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/DigestEncodeFunction.java index 5a91f4a55e4..9906b42da84 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/DigestEncodeFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/DigestEncodeFunction.java @@ -20,8 +20,8 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.codec.binary.Hex; @@ -51,7 +51,7 @@ public class DigestEncodeFunction extends AbstractFunction { * The algorithm names in this section can be specified when generating an * instance of MessageDigest: MD5 SHA-1 SHA-256 SHA-384 SHA-512 */ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__digest"; // Number of parameters expected - used to reject invalid calls diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeHtml.java b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeHtml.java index 7a007880a28..4b3d4186c81 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeHtml.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeHtml.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.text.StringEscapeUtils; @@ -48,7 +48,7 @@ */ public class EscapeHtml extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__escapeHtml"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeOroRegexpChars.java b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeOroRegexpChars.java index ef8dfd5e48f..01a24485ed4 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeOroRegexpChars.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeOroRegexpChars.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -37,7 +37,7 @@ public class EscapeOroRegexpChars extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(EscapeOroRegexpChars.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__escapeOroRegexpChars"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeXml.java b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeXml.java index bde6cb777cc..4dce679a768 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/EscapeXml.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/EscapeXml.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.text.StringEscapeUtils; @@ -45,7 +45,7 @@ */ public class EscapeXml extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__escapeXml"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/EvalFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/EvalFunction.java index 5c31d1b8d14..33c90be05f4 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/EvalFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/EvalFunction.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -36,7 +36,7 @@ */ public class EvalFunction extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__eval"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/EvalVarFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/EvalVarFunction.java index f28fce5dbc7..4d3521e81e3 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/EvalVarFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/EvalVarFunction.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -41,7 +41,7 @@ public class EvalVarFunction extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(EvalVarFunction.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__evalVar"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/FileToString.java b/src/functions/src/main/java/org/apache/jmeter/functions/FileToString.java index 1d147d0cb13..519fb699193 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/FileToString.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/FileToString.java @@ -19,8 +19,8 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.io.FileUtils; @@ -53,7 +53,7 @@ public class FileToString extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(FileToString.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__FileToString";//$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Groovy.java b/src/functions/src/main/java/org/apache/jmeter/functions/Groovy.java index ef0d4500731..5e23c7b5a36 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Groovy.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Groovy.java @@ -21,8 +21,8 @@ import java.io.Reader; import java.nio.charset.Charset; import java.nio.file.Files; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -51,7 +51,7 @@ public class Groovy extends AbstractFunction { private static final String GROOVY_ENGINE_NAME = "groovy"; - private static final List DESCRIPTION = new LinkedList<>(); + private static final List DESCRIPTION = new ArrayList<>(); private static final String KEY = "__groovy"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/IntSum.java b/src/functions/src/main/java/org/apache/jmeter/functions/IntSum.java index 3016974e5b5..92019be77c7 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/IntSum.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/IntSum.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -34,7 +34,7 @@ * @since 1.8.1 */ public class IntSum extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__intSum"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/IsPropDefined.java b/src/functions/src/main/java/org/apache/jmeter/functions/IsPropDefined.java index 039b3d28061..eb86e50151f 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/IsPropDefined.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/IsPropDefined.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -32,7 +32,7 @@ * @since 4.0 */ public class IsPropDefined extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__isPropDefined"; // Number of parameters expected - used to reject invalid calls diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/IsVarDefined.java b/src/functions/src/main/java/org/apache/jmeter/functions/IsVarDefined.java index 0eddf5b2e2f..edb8515e6a9 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/IsVarDefined.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/IsVarDefined.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -34,7 +34,7 @@ */ public class IsVarDefined extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__isVarDefined"; // Number of parameters expected - used to reject invalid calls private static final int MIN_PARAMETER_COUNT = 1; diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/IterationCounter.java b/src/functions/src/main/java/org/apache/jmeter/functions/IterationCounter.java index 4b5d8554905..ad435504d0c 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/IterationCounter.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/IterationCounter.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -36,7 +36,7 @@ */ public class IterationCounter extends AbstractFunction implements ThreadListener { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__counter"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/JavaScript.java b/src/functions/src/main/java/org/apache/jmeter/functions/JavaScript.java index 1236ead10aa..b478417144a 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/JavaScript.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/JavaScript.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import javax.script.Bindings; @@ -66,7 +66,7 @@ private static class LazyHolder { private static ScriptEngineManager getInstance() { return LazyHolder.INSTANCE; } - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__javaScript"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl2Function.java b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl2Function.java index 2c81d6700e2..7b6c185b27e 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl2Function.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl2Function.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.jexl2.JexlContext; @@ -47,7 +47,7 @@ public class Jexl2Function extends AbstractFunction implements ThreadListener { private static final String KEY = "__jexl2"; //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final ThreadLocal threadLocalJexl = new ThreadLocal<>(); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java index 6437bc1c086..ac74281d479 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Jexl3Function.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.jexl3.JexlBuilder; @@ -48,7 +48,7 @@ public class Jexl3Function extends AbstractFunction implements ThreadListener { private static final String KEY = "__jexl3"; //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final ThreadLocal threadLocalJexl = ThreadLocal .withInitial(Jexl3Function::createJexlEngine); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java index 44abc6bbdfb..33f736a42e9 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -48,7 +48,7 @@ public class LogFunction extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(LogFunction.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__log"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction2.java b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction2.java index 64e330bdc91..9f45af1ae44 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction2.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction2.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -46,7 +46,7 @@ public class LogFunction2 extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(LogFunction2.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__logn"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/LongSum.java b/src/functions/src/main/java/org/apache/jmeter/functions/LongSum.java index 7f2184d1d9b..37a8e8de517 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/LongSum.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/LongSum.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -34,7 +34,7 @@ */ public class LongSum extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__longSum"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Property.java b/src/functions/src/main/java/org/apache/jmeter/functions/Property.java index 5a8d7ce5a23..b2168a307fa 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Property.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Property.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -43,7 +43,7 @@ */ public class Property extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__property"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Property2.java b/src/functions/src/main/java/org/apache/jmeter/functions/Property2.java index 67948fb7160..701dd0fd46a 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Property2.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Property2.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -48,7 +48,7 @@ */ public class Property2 extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__P"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Random.java b/src/functions/src/main/java/org/apache/jmeter/functions/Random.java index 92a4bab8f0b..20921a187d1 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Random.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Random.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -35,7 +35,7 @@ */ public class Random extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__Random"; //$NON-NLS-1$ static { diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/RandomFromMultipleVars.java b/src/functions/src/main/java/org/apache/jmeter/functions/RandomFromMultipleVars.java index 8d916f42c81..eacf8bcf511 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/RandomFromMultipleVars.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/RandomFromMultipleVars.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -45,7 +44,7 @@ public class RandomFromMultipleVars extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(RandomFromMultipleVars.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__RandomFromMultipleVars"; //$NON-NLS-1$ private static final String SEPARATOR = "\\|"; //$NON-NLS-1$ static { diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java b/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java index 495981ded7e..fd39001a15e 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.lang3.RandomStringUtils; @@ -39,7 +39,7 @@ public class RandomString extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(RandomString.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__RandomString"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/RegexFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/RegexFunction.java index 7b6115ae8c2..71ffd73cd27 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/RegexFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/RegexFunction.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -56,7 +55,7 @@ public class RegexFunction extends AbstractFunction { private Object[] values;// Parameters are stored here - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String TEMPLATE_PATTERN = "\\$(\\d+)\\$"; //$NON-NLS-1$ /** initialised to the regex \$(\d+)\$ */ @@ -248,7 +247,7 @@ public void setParameters(Collection parameters) throws Invali private Object[] generateTemplate(String rawTemplate) { List pieces = new ArrayList<>(); // String or Integer - List combined = new LinkedList<>(); + List combined = new ArrayList<>(); PatternMatcher matcher = JMeterUtils.getMatcher(); Util.split(pieces, matcher, templatePattern, rawTemplate); PatternMatcherInput input = new PatternMatcherInput(rawTemplate); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/SamplerName.java b/src/functions/src/main/java/org/apache/jmeter/functions/SamplerName.java index 7c5818e1950..eedb707b96f 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/SamplerName.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/SamplerName.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -35,7 +35,7 @@ public class SamplerName extends AbstractFunction { private static final String KEY = "__samplerName"; //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); static { desc.add(JMeterUtils.getResString("function_name_paropt")); //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/SetProperty.java b/src/functions/src/main/java/org/apache/jmeter/functions/SetProperty.java index 8b812bffd86..7811c5686c1 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/SetProperty.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/SetProperty.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -42,7 +42,7 @@ */ public class SetProperty extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__setProperty"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/SplitFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/SplitFunction.java index ab349664967..17e8bb10120 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/SplitFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/SplitFunction.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -56,7 +56,7 @@ public class SplitFunction extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(SplitFunction.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__split";// $NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java index 559e3286d01..201fd84ad92 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java @@ -21,8 +21,8 @@ import java.io.FileReader; import java.io.IOException; import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.io.IOUtils; @@ -73,7 +73,7 @@ public class StringFromFile extends AbstractFunction implements TestStateListene private static final Logger log = LoggerFactory.getLogger(StringFromFile.class); // Only modified by static block so no need to synchronize subsequent read-only access - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__StringFromFile";//$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/StringToFile.java b/src/functions/src/main/java/org/apache/jmeter/functions/StringToFile.java index 8f13a8569b8..9116a3c88e7 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/StringToFile.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/StringToFile.java @@ -23,8 +23,8 @@ import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; @@ -56,7 +56,7 @@ */ public class StringToFile extends AbstractFunction { private static final Logger log = LoggerFactory.getLogger(StringToFile.class); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__StringToFile";//$NON-NLS-1$ private static final ConcurrentHashMap lockMap = new ConcurrentHashMap<>(); private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\\\n"); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/TestPlanName.java b/src/functions/src/main/java/org/apache/jmeter/functions/TestPlanName.java index c316db776b9..c0ab9e8a943 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/TestPlanName.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/TestPlanName.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -32,7 +32,7 @@ */ public class TestPlanName extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__TestPlanName"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/ThreadGroupName.java b/src/functions/src/main/java/org/apache/jmeter/functions/ThreadGroupName.java index 580f8eb2b5b..e465f000ae7 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/ThreadGroupName.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/ThreadGroupName.java @@ -17,7 +17,7 @@ package org.apache.jmeter.functions; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.jmeter.samplers.SampleResult; @@ -34,7 +34,7 @@ public class ThreadGroupName extends AbstractFunctionByKey { private static final String KEY = "__threadGroupName"; //$NON-NLS-1$ - private static final List DESC = new LinkedList<>(); + private static final List DESC = new ArrayList<>(); public ThreadGroupName() { super(KEY, 0); //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/ThreadNumber.java b/src/functions/src/main/java/org/apache/jmeter/functions/ThreadNumber.java index 0a9ab105082..0c353c32e6c 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/ThreadNumber.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/ThreadNumber.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -33,7 +33,7 @@ public class ThreadNumber extends AbstractFunction { private static final String KEY = "__threadNum"; //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); /** {@inheritDoc} */ @Override diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java index f0d74299069..fa9462f5f9c 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java @@ -18,10 +18,10 @@ package org.apache.jmeter.functions; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -44,7 +44,7 @@ public class TimeFunction extends AbstractFunction { private static final Pattern DIVISOR_PATTERN = Pattern.compile("/\\d+"); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); // Only modified in class init private static final Map aliases = new HashMap<>(); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/UnEscape.java b/src/functions/src/main/java/org/apache/jmeter/functions/UnEscape.java index 917bda3e899..910c4bb48f6 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/UnEscape.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/UnEscape.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.text.StringEscapeUtils; @@ -38,7 +38,7 @@ */ public class UnEscape extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__unescape"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/UnEscapeHtml.java b/src/functions/src/main/java/org/apache/jmeter/functions/UnEscapeHtml.java index 940349e2912..97a8bafa9c7 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/UnEscapeHtml.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/UnEscapeHtml.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.commons.text.StringEscapeUtils; @@ -44,7 +44,7 @@ */ public class UnEscapeHtml extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__unescapeHtml"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/UrlDecode.java b/src/functions/src/main/java/org/apache/jmeter/functions/UrlDecode.java index 51e3ff9a2b4..a31f1aa2a40 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/UrlDecode.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/UrlDecode.java @@ -21,8 +21,8 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -39,7 +39,7 @@ public class UrlDecode extends AbstractFunction { private static final String CHARSET_ENCODING = StandardCharsets.UTF_8.name(); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__urldecode"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/UrlEncode.java b/src/functions/src/main/java/org/apache/jmeter/functions/UrlEncode.java index 6a728cd4269..410ac89a585 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/UrlEncode.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/UrlEncode.java @@ -21,8 +21,8 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -39,7 +39,7 @@ public class UrlEncode extends AbstractFunction { private static final String CHARSET_ENCODING = StandardCharsets.UTF_8.name(); - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__urlencode"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Uuid.java b/src/functions/src/main/java/org/apache/jmeter/functions/Uuid.java index 37d883e931e..16461968ccd 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Uuid.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Uuid.java @@ -17,8 +17,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -38,7 +38,7 @@ */ public class Uuid extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__UUID"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/Variable.java b/src/functions/src/main/java/org/apache/jmeter/functions/Variable.java index 4773ec51468..18ee52db415 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/Variable.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/Variable.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -41,7 +41,7 @@ */ public class Variable extends AbstractFunction { - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private static final String KEY = "__V"; //$NON-NLS-1$ diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java b/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java index 6ef75d8c619..6c1f60aa95b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java @@ -18,8 +18,8 @@ package org.apache.jmeter.functions; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jmeter.engine.util.CompoundVariable; @@ -50,7 +50,7 @@ public class XPath extends AbstractFunction { private static final String KEY = "__XPath"; // Function name //$NON-NLS-1$ - private static final List desc = new LinkedList<>(); + private static final List desc = new ArrayList<>(); private Object[] values; // Parameter list diff --git a/src/jorphan/src/main/java/org/apache/jorphan/collections/ListedHashTree.java b/src/jorphan/src/main/java/org/apache/jorphan/collections/ListedHashTree.java index 9f5fbe962c3..1a7d58e34b9 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/collections/ListedHashTree.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/collections/ListedHashTree.java @@ -21,8 +21,8 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import org.apache.jorphan.util.JMeterError; @@ -43,7 +43,7 @@ public class ListedHashTree extends HashTree implements Serializable, Cloneable public ListedHashTree() { super(); - order = new LinkedList<>(); + order = new ArrayList<>(); } public ListedHashTree(Object key) { diff --git a/src/jorphan/src/main/java/org/apache/jorphan/collections/SearchByClass.java b/src/jorphan/src/main/java/org/apache/jorphan/collections/SearchByClass.java index cc6e196d9ed..22786324935 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/collections/SearchByClass.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/collections/SearchByClass.java @@ -17,9 +17,9 @@ package org.apache.jorphan.collections; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -52,7 +52,7 @@ * Class that should be searched for */ public class SearchByClass implements HashTreeTraverser { - private final List objectsOfClass = new LinkedList<>(); + private final List objectsOfClass = new ArrayList<>(); private final Map subTrees = new HashMap<>(); diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledChoice.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledChoice.java index 0dc92f19c3a..3df876004a4 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledChoice.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledChoice.java @@ -23,7 +23,6 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import javax.swing.JButton; @@ -112,7 +111,7 @@ public JLabeledChoice(String pLabel, String[] items, boolean editable, boolean w */ @Override public List getComponentList() { - List comps = new LinkedList<>(); + List comps = new ArrayList<>(); comps.add(mLabel); comps.add(choiceList); return comps; diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextArea.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextArea.java index 9cbaaa0827b..092b0508b2e 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextArea.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextArea.java @@ -21,7 +21,6 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import javax.swing.JComponent; @@ -92,7 +91,7 @@ public JLabeledTextArea(String pLabel, Document docModel) { */ @Override public List getComponentList() { - List comps = new LinkedList<>(); + List comps = new ArrayList<>(); comps.add(mLabel); comps.add(mTextArea); return comps; diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextField.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextField.java index dea4c7e0d70..d7f4e5c090c 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextField.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JLabeledTextField.java @@ -22,7 +22,6 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import javax.swing.JComponent; @@ -115,7 +114,7 @@ public JLabeledTextField(String pLabel, int size, Color bk, boolean editable) { */ @Override public List getComponentList() { - List comps = new LinkedList<>(); + List comps = new ArrayList<>(); comps.add(mLabel); comps.add(mTextField); return comps; diff --git a/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java b/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java index 41bd8b7e6c9..1b9def6a1d2 100644 --- a/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java +++ b/src/launcher/src/main/java/org/apache/jmeter/NewDriver.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; @@ -61,7 +60,7 @@ public final class NewDriver { private static final List EXCEPTIONS_IN_INIT = new ArrayList<>(); static { - final List jars = new LinkedList<>(); + final List jars = new ArrayList<>(); final String initiaClasspath = System.getProperty(JAVA_CLASS_PATH); // Find JMeter home dir from the initial classpath @@ -342,10 +341,12 @@ private static String getCommandLineArgument(String[] args, int id, String name) /* * If the fileName contains at least one set of paired single-quotes, reformat using DateFormat */ + @SuppressWarnings("JdkObsolete") private static String replaceDateFormatInFileName(String fileName) { try { StringBuilder builder = new StringBuilder(); + // TODO: replace with java.time.* final Date date = new Date(); int fromIndex = 0; int begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$ diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java index 1f9333401e8..13a67eb0038 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java @@ -20,7 +20,6 @@ import java.io.Serializable; import java.net.MalformedURLException; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -140,7 +139,7 @@ public void addConfigElement(ConfigElement config) { private void addFormUrls(Document html, HTTPSampleResult result, HTTPSamplerBase config, List potentialLinks) { NodeList rootList = html.getChildNodes(); - List urls = new LinkedList<>(); + List urls = new ArrayList<>(); for (int x = 0; x < rootList.getLength(); x++) { urls.addAll(HtmlParsingUtils.createURLFromForm(rootList.item(x), result.getURL())); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java index 01bafe201a1..3235bbd008a 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java @@ -37,10 +37,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.Deque; import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -768,6 +768,7 @@ public void stopProxy() { } } + @SuppressWarnings("JdkObsolete") public String[] getCertificateDetails() { if (isDynamicMode()) { try { @@ -1008,6 +1009,7 @@ private void addTransactionController(final JMeterTreeModel model, final JMeterT * @param node Sampler node in where we will add the timers * @param deltaT Time interval from the previous request */ + @SuppressWarnings("JdkObsolete") private void addTimers(JMeterTreeModel model, JMeterTreeNode node, long deltaT) { TestPlan variables = new TestPlan(); variables.addParameter("T", Long.toString(deltaT)); // $NON-NLS-1$ @@ -1102,9 +1104,10 @@ public JMeterTreeNode findTargetControllerNode() { * @return a collection of applicable objects of the given class. */ // TODO - could be converted to generic class? + @SuppressWarnings("JdkObsolete") private Collection findApplicableElements(JMeterTreeNode myTarget, Class myClass, boolean ascending) { JMeterTreeModel treeModel = getJmeterTreeModel(); - LinkedList elements = new LinkedList<>(); + Deque elements = new ArrayDeque<>(); // Look for elements directly within the HTTP proxy: JMeterTreeNode node = treeModel.getNodeOf(this); @@ -1400,6 +1403,7 @@ private void replaceValues(TestElement sampler, TestElement[] configs, Collectio * * @param event sampling event to be delivered */ + @SuppressWarnings("JdkObsolete") private void notifySampleListeners(SampleEvent event) { JMeterTreeModel treeModel = getJmeterTreeModel(); JMeterTreeNode myNode = treeModel.getNodeOf(this); @@ -1421,6 +1425,7 @@ private void notifySampleListeners(SampleEvent event) { * This will notify test listeners directly within the Proxy that the 'test' * (here meaning the proxy recording) has started. */ + @SuppressWarnings("JdkObsolete") private void notifyTestListenersOfStart() { JMeterTreeModel treeModel = getJmeterTreeModel(); JMeterTreeNode myNode = treeModel.getNodeOf(this); @@ -1443,6 +1448,7 @@ private void notifyTestListenersOfStart() { * This will notify test listeners directly within the Proxy that the 'test' * (here meaning the proxy recording) has ended. */ + @SuppressWarnings("JdkObsolete") private void notifyTestListenersOfEnd() { JMeterTreeModel treeModel = getJmeterTreeModel(); JMeterTreeNode myNode = treeModel.getNodeOf(this); @@ -1493,6 +1499,7 @@ private void initKeyStore() throws IOException, GeneralSecurityException { /** * Initialise the user-provided keystore */ + @SuppressWarnings("JdkObsolete") private void initUserKeyStore() { try { keyStore = getKeyStore(storePassword.toCharArray()); @@ -1514,6 +1521,7 @@ private void initUserKeyStore() { /** * Initialise the dynamic domain keystore */ + @SuppressWarnings("JdkObsolete") private void initDynamicKeyStore() throws IOException, GeneralSecurityException { if (storePassword != null) { // Assume we have already created the store try { @@ -1608,6 +1616,7 @@ KeyStore updateKeyStore(String port, String host) throws IOException, GeneralSec /** * Initialise the single key JMeter keystore (original behaviour) */ + @SuppressWarnings("JdkObsolete") private void initJMeterKeyStore() throws IOException, GeneralSecurityException { if (storePassword != null) { // Assume we have already created the store try { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java index d79428c3f89..7846a227437 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java @@ -36,9 +36,10 @@ import java.io.IOException; import java.net.BindException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; +import java.util.Collections; import java.util.List; import javax.swing.BorderFactory; @@ -364,10 +365,8 @@ protected void setExcludeListInProxyControl(ProxyControl element) { private List getDataList(PowerTableModel pModel, String colName) { String[] dataArray = pModel.getData().getColumn(colName); - List list = new LinkedList<>(); - for (String data : dataArray) { - list.add(data); - } + List list = new ArrayList<>(); + Collections.addAll(list, dataArray); return list; } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java index bf8daefecbe..687b8b8eafc 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPArgument.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.jmeter.config.Argument; @@ -265,7 +265,7 @@ public String getEncodedName() { * @param args collection of {@link Argument} and/or {@link HTTPArgument} entries */ public static void convertArgumentsToHTTP(Arguments args) { - List newArguments = new LinkedList<>(); + List newArguments = new ArrayList<>(); for (JMeterProperty jMeterProperty : args.getArguments()) { Argument arg = (Argument) jMeterProperty.getObjectValue(); if (!(arg instanceof HTTPArgument)) { From db768c0e6fbffce8b8a1c64c867e47682a54866c Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:27:11 +0300 Subject: [PATCH 08/40] Remove uses of deprecated APIs --- .../jmeter/assertions/XMLAssertion.java | 10 ++++++--- .../jmeter/timers/PoissonRandomTimer.java | 1 + .../apache/jmeter/visualizers/AxisGraph.java | 3 ++- .../visualizers/RespTimeGraphChart.java | 9 ++++---- .../jmeter/visualizers/StatVisualizer.java | 2 +- .../backend/influxdb/HttpMetricsSender.java | 3 ++- .../jmeter/control/gui/WorkBenchGui.java | 12 +++++----- .../jmeter/functions/gui/FunctionHelper.java | 13 ++++++++++- .../org/apache/jmeter/gui/GUIFactory.java | 5 +++-- .../java/org/apache/jmeter/gui/NamePanel.java | 8 ++++--- .../apache/jmeter/gui/action/KeyStrokes.java | 10 ++++++++- .../gui/logging/GuiLogEventAppender.java | 3 ++- .../jmeter/gui/tree/JMeterTreeListener.java | 4 +++- .../jmeter/gui/tree/JMeterTreeModel.java | 8 +++++-- .../gui/util/HeaderAsPropertyRenderer.java | 1 + .../jmeter/gui/util/TristateCheckBox.java | 1 + .../apache/jmeter/save/CSVSaveService.java | 4 +++- .../save/converters/HashTreeConverter.java | 6 ++--- .../converters/MultiPropertyConverter.java | 4 ++-- .../converters/SampleResultConverter.java | 8 +++---- .../save/converters/TestElementConverter.java | 4 ++-- .../TestElementPropertyConverter.java | 4 ++-- .../TestResultWrapperConverter.java | 2 +- .../util/SecurityProviderLoaderTest.java | 2 ++ .../org/apache/jmeter/junit/JMeterTest.java | 6 +++-- .../jmeter/functions/StringFromFile.java | 4 ++-- .../cli/avalon/CLOptionDescriptor.java | 2 +- .../org/apache/jorphan/exec/StreamCopier.java | 12 ++-------- .../org/apache/jorphan/gui/MenuScroller.java | 1 + .../org/apache/jorphan/util/HeapDumper.java | 1 + .../org/apache/jorphan/util/JOrphanUtils.java | 2 ++ .../protocol/ftp/sampler/FTPSampler.java | 10 ++++----- .../protocol/http/control/CacheManager.java | 4 ++++ .../http/control/HC4CookieHandler.java | 4 ++++ .../http/parser/HtmlParsingUtils.java | 3 +++ .../protocol/http/proxy/ProxyControl.java | 4 ++-- .../protocol/http/sampler/HTTPFileImpl.java | 2 +- .../protocol/http/sampler/HTTPHC4Impl.java | 4 +++- .../http/sampler/HTTPSamplerBase.java | 8 +++---- .../http/util/HTTPResultConverter.java | 4 ++-- .../http/control/TestAuthorization.java | 2 +- .../http/control/TestCacheManagerBase.java | 4 ++++ .../http/control/TestCacheManagerHC4.java | 1 + .../http/proxy/TestHttpRequestHdr.java | 22 +++++++++---------- .../protocol/java/sampler/JavaSampler.java | 1 + .../jdbc/config/DataSourceElement.java | 2 +- .../org/apache/jmeter/protocol/jms/Utils.java | 2 ++ .../jms/control/gui/JMSSamplerGui.java | 8 +++++-- .../jms/sampler/PublisherSampler.java | 2 +- .../jms/sampler/SubscriberSampler.java | 2 +- .../protocol/smtp/sampler/SmtpSampler.java | 2 +- .../tcp/sampler/AbstractTCPClient.java | 1 + .../tcp/sampler/BinaryTCPClientImpl.java | 2 -- 53 files changed, 158 insertions(+), 91 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/XMLAssertion.java b/src/components/src/main/java/org/apache/jmeter/assertions/XMLAssertion.java index 5e820696da4..6aa6d113ae9 100644 --- a/src/components/src/main/java/org/apache/jmeter/assertions/XMLAssertion.java +++ b/src/components/src/main/java/org/apache/jmeter/assertions/XMLAssertion.java @@ -21,6 +21,9 @@ import java.io.Serializable; import java.io.StringReader; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; + import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testelement.AbstractTestElement; import org.apache.jmeter.testelement.ThreadListener; @@ -29,7 +32,6 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; /** * Checks if the result is a well-formed XML content using {@link XMLReader} @@ -45,10 +47,12 @@ public class XMLAssertion extends AbstractTestElement implements Serializable, A @Override protected XMLReader initialValue() { try { - XMLReader reader = XMLReaderFactory.createXMLReader(); + XMLReader reader = SAXParserFactory.newInstance() + .newSAXParser() + .getXMLReader(); reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return reader; - } catch (SAXException e) { + } catch (SAXException | ParserConfigurationException e) { log.error("Error initializing XMLReader in XMLAssertion", e); return null; } diff --git a/src/components/src/main/java/org/apache/jmeter/timers/PoissonRandomTimer.java b/src/components/src/main/java/org/apache/jmeter/timers/PoissonRandomTimer.java index 466e212fceb..60ddda96b8e 100644 --- a/src/components/src/main/java/org/apache/jmeter/timers/PoissonRandomTimer.java +++ b/src/components/src/main/java/org/apache/jmeter/timers/PoissonRandomTimer.java @@ -36,6 +36,7 @@ public class PoissonRandomTimer extends RandomTimer implements Serializable { /** * */ + @SuppressWarnings("FloatingPointLiteralPrecision") private static final double[] LOG_FACTORIAL = { 0.000000000000000, diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java b/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java index 3de8a949b64..c241a4f4793 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java @@ -25,6 +25,7 @@ import java.awt.LayoutManager; import java.awt.Paint; import java.math.BigDecimal; +import java.math.RoundingMode; import javax.swing.JPanel; import javax.swing.UIManager; @@ -398,7 +399,7 @@ private void drawSample(String _title, int _maxLength, String[] _xAxisLabels, // Y Axis try { BigDecimal round = BigDecimal.valueOf(max / 1000d); - round = round.setScale(0, BigDecimal.ROUND_UP); + round = round.setScale(0, RoundingMode.HALF_EVEN); double topValue = round.doubleValue() * 1000; yaxis.setUserDefinedScale(0, 500); yaxis.setNumItems((int) (topValue / 500)+1); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java index d21822472a5..f1216f787e2 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java @@ -28,6 +28,7 @@ import java.awt.Shape; import java.awt.Stroke; import java.math.BigDecimal; +import java.math.RoundingMode; import javax.swing.JPanel; @@ -281,7 +282,7 @@ private void drawSample(String _title, String[] _xAxisLabels, double[][] _data, int _width, int _height, int _incrScaleYAxis, Color[] _color, Font legendFont, Graphics g) { - double max = maxYAxisScale > 0 ? maxYAxisScale : getTopValue(findMax(_data), BigDecimal.ROUND_UP); // define max scale y axis + double max = maxYAxisScale > 0 ? maxYAxisScale : getTopValue(findMax(_data), RoundingMode.HALF_EVEN); // define max scale y axis try { // if the title graph is empty, we can assume some default if (_title.length() == 0 ) { @@ -331,7 +332,7 @@ private void drawSample(String _title, String[] _xAxisLabels, double incrYAxis = max / numInterval; double incrTopValue = _incrScaleYAxis; if (_incrScaleYAxis == 0) { - incrTopValue = getTopValue(incrYAxis, BigDecimal.ROUND_HALF_UP); + incrTopValue = getTopValue(incrYAxis, RoundingMode.HALF_EVEN); } if (incrTopValue < 1) { incrTopValue = 1.0d; // Increment cannot be < 1 @@ -368,7 +369,7 @@ private void drawSample(String _title, String[] _xAxisLabels, } } - private int getTopValue(double value, int roundMode) { + private int getTopValue(double value, RoundingMode roundingMode) { String maxStr = String.valueOf(Math.round(value)); StringBuilder divValueStr = new StringBuilder(maxStr.length()+1); divValueStr.append("1"); @@ -377,7 +378,7 @@ private int getTopValue(double value, int roundMode) { } int divValueInt = Integer.parseInt(divValueStr.toString()); BigDecimal round = BigDecimal.valueOf(value / divValueInt); - round = round.setScale(0, roundMode); + round = round.setScale(0, roundingMode); int topValue = round.intValue() * divValueInt; return topValue; } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/StatVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/StatVisualizer.java index 13b58a54dd6..6f062b8a51a 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/StatVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/StatVisualizer.java @@ -166,7 +166,7 @@ private void init() { // WARNING: called from ctor so must not be overridden (i. JTable myJTable = new JTable(model); myJTable.setRowSorter(new ObjectTableSorter(model).fixLastRow()); JMeterUtils.applyHiDPI(myJTable); - HeaderAsPropertyRendererWrapper.setupDefaultRenderer(myJTable, StatGraphVisualizer.getColumnsMsgParameters()); + HeaderAsPropertyRendererWrapper.setupDefaultRenderer(myJTable); myJTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); RendererUtils.applyRenderers(myJTable, StatGraphVisualizer.getRenderers()); JScrollPane myScrollPane = new JScrollPane(myJTable); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java index a40c1144526..9bbc31935a0 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java @@ -239,6 +239,7 @@ private static String getBody(final HttpResponse response) { } @Override + @SuppressWarnings("deprecation") public void destroy() { // Give some time to send last metrics before shutting down log.info("Destroying "); @@ -250,7 +251,7 @@ public void destroy() { if (httpRequest != null) { httpRequest.abort(); } - IOUtils.closeQuietly(httpClient); + IOUtils.closeQuietly(httpClient, null); } } diff --git a/src/core/src/main/java/org/apache/jmeter/control/gui/WorkBenchGui.java b/src/core/src/main/java/org/apache/jmeter/control/gui/WorkBenchGui.java index 4caec0d822b..89b9adfef61 100644 --- a/src/core/src/main/java/org/apache/jmeter/control/gui/WorkBenchGui.java +++ b/src/core/src/main/java/org/apache/jmeter/control/gui/WorkBenchGui.java @@ -30,7 +30,6 @@ import org.apache.jmeter.gui.util.MenuFactory; import org.apache.jmeter.gui.util.VerticalPanel; import org.apache.jmeter.testelement.TestElement; -import org.apache.jmeter.testelement.WorkBench; import org.apache.jmeter.util.JMeterUtils; /** @@ -69,16 +68,18 @@ public Collection getMenuCategories() { /* Implements JMeterGUIComponent.createTestElement() */ @Override public TestElement createTestElement() { - WorkBench wb = new WorkBench(); + @SuppressWarnings("deprecation") + org.apache.jmeter.testelement.WorkBench wb = new org.apache.jmeter.testelement.WorkBench(); modifyTestElement(wb); return wb; } /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */ @Override + @SuppressWarnings("deprecation") public void modifyTestElement(TestElement wb) { super.configureTestElement(wb); - ((WorkBench)wb).setSaveWorkBench(saveWorkBench.isSelected()); + ((org.apache.jmeter.testelement.WorkBench) wb).setSaveWorkBench(saveWorkBench.isSelected()); } /** @@ -91,10 +92,11 @@ public void modifyTestElement(TestElement wb) { * the TestElement to configure */ @Override + @SuppressWarnings("deprecation") public void configure(TestElement el) { super.configure(el); - if (el instanceof WorkBench) { - WorkBench tp = (WorkBench) el; + if (el instanceof org.apache.jmeter.testelement.WorkBench) { + org.apache.jmeter.testelement.WorkBench tp = (org.apache.jmeter.testelement.WorkBench) el; saveWorkBench.setSelected(tp.getSaveWorkBench()); } } diff --git a/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java b/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java index fbe18de2888..3437fd5c5a3 100644 --- a/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java +++ b/src/core/src/main/java/org/apache/jmeter/functions/gui/FunctionHelper.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -203,7 +204,17 @@ public void stateChanged(ChangeEvent event) { */ protected void initParameterPanel() throws InstantiationException, IllegalAccessException { Arguments args = new Arguments(); - Function function = CompoundVariable.getFunctionClass(getFunctionName(functionList.getText())).newInstance(); + Function function; + String functionName = getFunctionName(functionList.getText()); + try { + function = CompoundVariable.getFunctionClass(functionName) + .getDeclaredConstructor() + .newInstance(); + } catch (InvocationTargetException | NoSuchMethodException e) { + InstantiationException ex = new InstantiationException("Unable to instantiate " + functionName); + ex.initCause(e instanceof InvocationTargetException ? e.getCause() : e); + throw ex; + } List argumentDesc = function.getArgumentDesc(); for (String help : argumentDesc) { args.addArgument(help, ""); //$NON-NLS-1$ diff --git a/src/core/src/main/java/org/apache/jmeter/gui/GUIFactory.java b/src/core/src/main/java/org/apache/jmeter/gui/GUIFactory.java index 28b2b61fda7..7b88858db72 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/GUIFactory.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/GUIFactory.java @@ -17,6 +17,7 @@ package org.apache.jmeter.gui; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -158,14 +159,14 @@ public static void registerDisabledIcon(String key, ImageIcon icon) { * to be created */ public static void registerGUI(String key, Class guiClass, Class testClass) throws InstantiationException, - IllegalAccessException { + IllegalAccessException, NoSuchMethodException, InvocationTargetException { // TODO: This method doesn't appear to be used. JMeterGUIComponent gui; if (guiClass == TestBeanGUI.class) { gui = new TestBeanGUI(testClass); } else { - gui = (JMeterGUIComponent) guiClass.newInstance(); + gui = (JMeterGUIComponent) guiClass.getDeclaredConstructor().newInstance(); } GUI_MAP.put(key, gui); } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/NamePanel.java b/src/core/src/main/java/org/apache/jmeter/gui/NamePanel.java index 904e1dd9ca3..d109c1c13ec 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/NamePanel.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/NamePanel.java @@ -28,7 +28,6 @@ import javax.swing.JTextField; import org.apache.jmeter.testelement.TestElement; -import org.apache.jmeter.testelement.WorkBench; import org.apache.jmeter.testelement.property.StringProperty; import org.apache.jmeter.util.JMeterUtils; import org.apiguardian.api.API; @@ -140,7 +139,8 @@ public Collection getMenuCategories() { /** {@inheritDoc} */ @Override public TestElement createTestElement() { - WorkBench wb = new WorkBench(); + @SuppressWarnings("deprecation") + org.apache.jmeter.testelement.WorkBench wb = new org.apache.jmeter.testelement.WorkBench(); modifyTestElement(wb); return wb; } @@ -150,7 +150,9 @@ public TestElement createTestElement() { public void modifyTestElement(TestElement wb) { wb.setName(getName()); wb.setProperty(new StringProperty(TestElement.GUI_CLASS, this.getClass().getName())); - wb.setProperty(new StringProperty(TestElement.TEST_CLASS, WorkBench.class.getName())); + @SuppressWarnings("deprecation") + String className = org.apache.jmeter.testelement.WorkBench.class.getName(); + wb.setProperty(new StringProperty(TestElement.TEST_CLASS, className)); } /** diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/KeyStrokes.java b/src/core/src/main/java/org/apache/jmeter/gui/action/KeyStrokes.java index 67f3ddac684..34ef5f08402 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/KeyStrokes.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/KeyStrokes.java @@ -38,7 +38,7 @@ private KeyStrokes(){ static { int mask = KeyEvent.CTRL_DOWN_MASK; // This is better than nothing... try { - mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + mask = getMenuShortcutKeyMask(); } catch (java.awt.HeadlessException e) { // suppress the error if we are deliberately running headless if (!"true".equals(System.getProperty("java.awt.headless"))) { // $NON-NLS-1$ $NON-NLS-2$ @@ -48,6 +48,13 @@ private KeyStrokes(){ CONTROL_MASK = mask; } + @SuppressWarnings("deprecation") + private static int getMenuShortcutKeyMask() { + // getMenuShortcutKeyMask is deprecated since Java 10 + return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + } + + public static final KeyStroke COPY = KeyStroke.getKeyStroke(KeyEvent.VK_C, CONTROL_MASK); public static final KeyStroke DUPLICATE = KeyStroke.getKeyStroke(KeyEvent.VK_C, CONTROL_MASK | InputEvent.SHIFT_DOWN_MASK); public static final KeyStroke DEBUG_OFF = KeyStroke.getKeyStroke(KeyEvent.VK_D, CONTROL_MASK); @@ -113,6 +120,7 @@ private KeyStrokes(){ * @return true if event matches the keystroke definition */ public static boolean matches(KeyEvent e, KeyStroke k){ + @SuppressWarnings("deprecation") final int modifiersEx = e.getModifiersEx() | e.getModifiers();// Hack to get full modifier value return e.getKeyCode() == k.getKeyCode() && modifiersEx == k.getModifiers(); } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/logging/GuiLogEventAppender.java b/src/core/src/main/java/org/apache/jmeter/gui/logging/GuiLogEventAppender.java index fd6a2f9f302..c52dec0d227 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/logging/GuiLogEventAppender.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/logging/GuiLogEventAppender.java @@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.StringLayout; import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; @@ -40,7 +41,7 @@ public class GuiLogEventAppender extends AbstractAppender { protected GuiLogEventAppender(final String name, final Filter filter, final Layout layout, final boolean ignoreExceptions) { - super(name, filter, layout, ignoreExceptions); + super(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY); } @Override diff --git a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeListener.java b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeListener.java index f5944626925..e2ccf377db5 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeListener.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeListener.java @@ -237,7 +237,9 @@ public void keyTyped(KeyEvent e) { } private boolean isRightClick(MouseEvent e) { - return e.isPopupTrigger() || (InputEvent.BUTTON2_MASK & e.getModifiers()) > 0 || (InputEvent.BUTTON3_MASK == e.getModifiers()); + return e.isPopupTrigger() || + (InputEvent.BUTTON2_DOWN_MASK & e.getModifiersEx()) > 0 || + (InputEvent.BUTTON3_DOWN_MASK == e.getModifiersEx()); } private void displayPopUp(MouseEvent e) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java index a771bae0404..c64de1f50b0 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java @@ -34,7 +34,6 @@ import org.apache.jmeter.gui.util.MenuFactory; import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestPlan; -import org.apache.jmeter.testelement.WorkBench; import org.apache.jorphan.collections.HashTree; import org.apache.jorphan.collections.ListedHashTree; @@ -122,7 +121,7 @@ public HashTree addSubTree(HashTree subTree, JMeterTreeNode current) throws Ille userObject.setFunctionalMode(tp.isFunctionalMode()); userObject.setSerialized(tp.isSerialized()); addSubTree(subTree.getTree(item), current); - } else if (item instanceof WorkBench) { + } else if (isWorkbench(item)) { //Move item from WorkBench to TestPlan HashTree workbenchTree = subTree.getTree(item); if (!workbenchTree.isEmpty()) { @@ -135,6 +134,11 @@ public HashTree addSubTree(HashTree subTree, JMeterTreeNode current) throws Ille return getCurrentSubTree(current); } + @SuppressWarnings("deprecation") + private boolean isWorkbench(TestElement item) { + return item instanceof org.apache.jmeter.testelement.WorkBench; + } + /** * Add a {@link TestElement} to a {@link JMeterTreeNode} * @param component The {@link TestElement} to be used as data for the newly created node diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java b/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java index f36bba7121c..ce333ed4bf5 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java @@ -90,6 +90,7 @@ protected String getText(Object value, int row, int column) { * @param columnsMsgParameters ignored * @return the text */ + @SuppressWarnings("deprecation") static String getText(Object value, int row, int column, Object[][] columnsMsgParameters) { if (value == null){ return ""; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/TristateCheckBox.java b/src/core/src/main/java/org/apache/jmeter/gui/util/TristateCheckBox.java index df27755bf64..5b613df095c 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/TristateCheckBox.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/TristateCheckBox.java @@ -166,6 +166,7 @@ public synchronized void addMouseListener(MouseListener l) { } // Mostly delegates to model + @SuppressWarnings("deprecation") private void iterateState() { //Maybe do nothing at all? if (!getModel().isEnabled()) { diff --git a/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java b/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java index e34d773b832..72015831409 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java +++ b/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java @@ -249,7 +249,9 @@ private static SampleEvent makeResultFromDelimitedString( } if (saveConfig.saveSampleCount()) { - result = new StatisticalSampleResult(timeStamp, elapsed); + @SuppressWarnings("deprecation") + StatisticalSampleResult sampleResult = new StatisticalSampleResult(timeStamp, elapsed); + result = sampleResult; } else { result = new SampleResult(timeStamp, elapsed); } diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/HashTreeConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/HashTreeConverter.java index a4cec2ba772..3305570b14c 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/HashTreeConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/HashTreeConverter.java @@ -49,8 +49,8 @@ public boolean canConvert(@SuppressWarnings("rawtypes") Class arg0) { // supercl public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) { HashTree tree = (HashTree) arg0; for (Object item : tree.list()) { - writeItem(item, context, writer); - writeItem(tree.getTree(item), context, writer); + writeCompleteItem(item, context, writer); + writeCompleteItem(tree.getTree(item), context, writer); } } @@ -63,7 +63,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co HashTree tree = (HashTree) createCollection(context.getRequiredType()); while (reader.hasMoreChildren()) { reader.moveDown(); - Object item = readItem(reader, context, tree); + Object item = readBareItem(reader, context, tree); if (isKey) { tree.add(item); current = item; diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/MultiPropertyConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/MultiPropertyConverter.java index c0429990055..64988c6f316 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/MultiPropertyConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/MultiPropertyConverter.java @@ -54,7 +54,7 @@ public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingCon writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp.encode(prop.getName())); for (JMeterProperty jMeterProperty : prop) { - writeItem(jMeterProperty, context, writer); + writeCompleteItem(jMeterProperty, context, writer); } } @@ -65,7 +65,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co prop.setName(ConversionHelp.decode(reader.getAttribute(ConversionHelp.ATT_NAME))); while (reader.hasMoreChildren()) { reader.moveDown(); - JMeterProperty subProp = (JMeterProperty) readItem(reader, context, prop); + JMeterProperty subProp = (JMeterProperty) readBareItem(reader, context, prop); if (subProp != null) { // could be null if it has been deleted via NameUpdater prop.addProperty(subProp); } diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/SampleResultConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/SampleResultConverter.java index 7e95c355d0e..49cbb093b5b 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/SampleResultConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/SampleResultConverter.java @@ -141,7 +141,7 @@ protected void saveSamplerData(HierarchicalStreamWriter writer, MarshallingConte if (save.saveUrl()) { final URL url = res.getURL(); if (url != null) { - writeItem(url, context, writer); + writeCompleteItem(url, context, writer); } } } @@ -239,7 +239,7 @@ protected void saveSubResults(HierarchicalStreamWriter writer, MarshallingContex SampleResult[] subResults = res.getSubResults(); for (SampleResult subResult : subResults) { subResult.setSaveConfig(save); - writeItem(subResult, context, writer); + writeCompleteItem(subResult, context, writer); } } } @@ -261,7 +261,7 @@ protected void saveAssertions(HierarchicalStreamWriter writer, MarshallingContex if (save.saveAssertions()) { AssertionResult[] assertionResults = res.getAssertionResults(); for (AssertionResult assertionResult : assertionResults) { - writeItem(assertionResult, context, writer); + writeCompleteItem(assertionResult, context, writer); } } } @@ -368,7 +368,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co retrieveAttributes(reader, context, res); while (reader.hasMoreChildren()) { reader.moveDown(); - Object subItem = readItem(reader, context, res); + Object subItem = readBareItem(reader, context, res); retrieveItem(reader, context, res, subItem); reader.moveUp(); } diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementConverter.java index 7ccab4ba4a7..f477b323d9c 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementConverter.java @@ -70,7 +70,7 @@ public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingCon && !el.getClass().equals(TestPlan.class) )) { - writeItem(jmp, context, writer); + writeCompleteItem(jmp, context, writer); } } } @@ -102,7 +102,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co el.setProperty(TestElement.TEST_CLASS, targetName); while (reader.hasMoreChildren()) { reader.moveDown(); - JMeterProperty prop = (JMeterProperty) readItem(reader, context, el); + JMeterProperty prop = (JMeterProperty) readBareItem(reader, context, el); if (prop != null) { // could be null if it has been deleted via NameUpdater el.setProperty(prop); } diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementPropertyConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementPropertyConverter.java index 2cd43fd0a6d..50bfbff5876 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementPropertyConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/TestElementPropertyConverter.java @@ -71,7 +71,7 @@ public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingCon if (!(TestElement.COMMENTS.equals(jmp.getName()) && jmp.getStringValue().isEmpty())) { - writeItem(jmp, context, writer); + writeCompleteItem(jmp, context, writer); } } } @@ -106,7 +106,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co ConversionHelp.restoreSpecialProperties(te, reader); while (reader.hasMoreChildren()) { reader.moveDown(); - JMeterProperty subProp = (JMeterProperty) readItem(reader, context, prop); + JMeterProperty subProp = (JMeterProperty) readBareItem(reader, context, prop); if (subProp != null) { // could be null if it has been deleted via NameUpdater if (isHeader) { String name = subProp.getName(); diff --git a/src/core/src/main/java/org/apache/jmeter/save/converters/TestResultWrapperConverter.java b/src/core/src/main/java/org/apache/jmeter/save/converters/TestResultWrapperConverter.java index 42eb44b1d92..419457260d5 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/converters/TestResultWrapperConverter.java +++ b/src/core/src/main/java/org/apache/jmeter/save/converters/TestResultWrapperConverter.java @@ -91,7 +91,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co final ResultCollectorHelper resultCollectorHelper = (ResultCollectorHelper) context.get(SaveService.RESULTCOLLECTOR_HELPER_OBJECT); while (reader.hasMoreChildren()) { reader.moveDown(); - SampleResult sample = (SampleResult) readItem(reader, context, results); + SampleResult sample = (SampleResult) readBareItem(reader, context, results); if (resultCollectorHelper != null) { resultCollectorHelper.add(sample); } else { diff --git a/src/core/src/test/java/org/apache/jmeter/util/SecurityProviderLoaderTest.java b/src/core/src/test/java/org/apache/jmeter/util/SecurityProviderLoaderTest.java index a03a268e36e..ece1cbf6445 100644 --- a/src/core/src/test/java/org/apache/jmeter/util/SecurityProviderLoaderTest.java +++ b/src/core/src/test/java/org/apache/jmeter/util/SecurityProviderLoaderTest.java @@ -175,6 +175,7 @@ public static class DummyProvider extends Provider { private static final long serialVersionUID = 1L; public static final String PROVIDER_NAME = "DUMMY"; + @SuppressWarnings("deprecation") public DummyProvider() { super(PROVIDER_NAME, 1.0, PROVIDER_NAME); } @@ -187,6 +188,7 @@ public static class DummyProviderWithConfig extends Provider { private String config = null; + @SuppressWarnings("deprecation") public DummyProviderWithConfig() { super(PROVIDER_NAME, 1.0, PROVIDER_NAME); } diff --git a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java index a8cb5fb24d0..87a03ae61aa 100644 --- a/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java +++ b/src/dist-check/src/test/java/org/apache/jmeter/junit/JMeterTest.java @@ -28,6 +28,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.rmi.RemoteException; import java.util.Collection; import java.util.HashMap; @@ -508,8 +509,9 @@ private static Throwable instantiateClass(final String extendsClassName, final O Class c = Class.forName(className); try { // Try with a parameter-less constructor first - objects.add(c.newInstance()); - } catch (InstantiationException e) { + objects.add(c.getDeclaredConstructor().newInstance()); + } catch (InstantiationException | NoSuchMethodException | IllegalAccessException | + InvocationTargetException e) { caught = e; try { // Events often have this constructor diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java index 201fd84ad92..2b154c42077 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java @@ -222,8 +222,8 @@ private synchronized void openFile() { myBread = new BufferedReader(myFileReader); } catch (Exception e) { log.error("openFile() error: {}", e.toString());//$NON-NLS-1$ - IOUtils.closeQuietly(myFileReader); - IOUtils.closeQuietly(myBread); + IOUtils.closeQuietly(myFileReader, null); + IOUtils.closeQuietly(myBread, null); myBread = null; myFileReader = null; } diff --git a/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLOptionDescriptor.java b/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLOptionDescriptor.java index 864b55148b4..155a5a90741 100644 --- a/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLOptionDescriptor.java +++ b/src/jorphan/src/main/java/org/apache/commons/cli/avalon/CLOptionDescriptor.java @@ -125,7 +125,7 @@ private void checkFlags(final int flags) { * * @return the array of incompatible option ids */ - protected final int[] getIncompatible() { + final int[] getIncompatible() { return this.incompatible; } diff --git a/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java b/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java index 7dbe185b20d..ea7b7a56f8e 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java @@ -52,19 +52,11 @@ class StreamCopier extends Thread { @Override public void run() { final boolean isSystemOutput = os.equals(System.out) || os.equals(System.err); - try { + try (OutputStream ignored = isSystemOutput ? null : os; + InputStream ignored1 = is) { IOUtils.copyLarge(is, os); - if (!isSystemOutput){ - os.close(); - } - is.close(); } catch (IOException e) { log.warn("Error writing stream", e); - } finally { - IOUtils.closeQuietly(is); - if (!isSystemOutput){ - IOUtils.closeQuietly(os); - } } } diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java index e4d825f8a81..d1838dd884a 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java @@ -521,6 +521,7 @@ public void dispose() { * @see MenuScroller#dispose() */ @Override + @SuppressWarnings("deprecation") public void finalize() throws Throwable { dispose(); super.finalize(); diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java b/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java index 2be412b1e2d..3f71f346ddd 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/HeapDumper.java @@ -159,6 +159,7 @@ public static String dumpHeap(boolean live) throws Exception { * @return the name of the dump file that was created * @throws Exception if the MXBean cannot be found, or if there is a problem during invocation */ + @SuppressWarnings("JdkObsolete") public static String dumpHeap(File basedir, boolean live) throws Exception { SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd_hhmmss_SSS"); String stamp = timestampFormat.format(new Date()); diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java b/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java index 912c7f3b35f..d4f40e2e1a2 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java @@ -682,6 +682,7 @@ public static void canSafelyWriteToFolder(File folder, boolean deleteFolderIfExi * @param caseSensitive is case taken into account * @return array of Object where first row is the replaced text, second row is the number of replacement that occurred */ + @SuppressWarnings("JdkObsolete") public static Object[] replaceAllWithRegex( String source, String regex, String replacement, boolean caseSensitive) { java.util.regex.Pattern pattern = caseSensitive ? @@ -690,6 +691,7 @@ public static Object[] replaceAllWithRegex( final String replacementQuoted = Matcher.quoteReplacement(replacement); Matcher matcher = pattern.matcher(source); int totalReplaced = 0; + // Can be replaced with StringBuilder for Java 9+ StringBuffer result = new StringBuffer(); // NOSONAR Matcher#appendReplacement needs a StringBuffer while (matcher.find()) { matcher.appendReplacement(result, replacementQuoted); diff --git a/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java b/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java index b3aa7262f89..d2789a63fb8 100644 --- a/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java +++ b/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java @@ -236,7 +236,7 @@ public SampleResult sample(Entry e) { } } if (target == null){ - target=new NullOutputStream(); + target = NullOutputStream.NULL_OUTPUT_STREAM; } input = ftp.retrieveFileStream(remote); if (input == null){// Could not access file or other error @@ -252,8 +252,8 @@ public SampleResult sample(Entry e) { } } } finally { - IOUtils.closeQuietly(target); - IOUtils.closeQuietly(output); + IOUtils.closeQuietly(target, null); + IOUtils.closeQuietly(output, null); } } @@ -296,8 +296,8 @@ public SampleResult sample(Entry e) { // NOOP } } - IOUtils.closeQuietly(input); - IOUtils.closeQuietly(fileIS); + IOUtils.closeQuietly(input, null); + IOUtils.closeQuietly(fileIS, null); } res.sampleEnd(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java index 6a01fd69f67..c2f4fe33f17 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CacheManager.java @@ -63,6 +63,7 @@ public class CacheManager extends ConfigTestElement implements TestStateListener private static final Logger log = LoggerFactory.getLogger(CacheManager.class); + @SuppressWarnings("JdkObsolete") private static final Date EXPIRED_DATE = new Date(0L); private static final int DEFAULT_MAX_SIZE = 5000; private static final long ONE_YEAR_MS = 365*24*60*60*1000L; @@ -293,6 +294,7 @@ private Date extractExpiresDateFromExpires(String expires) { return expiresDate; } + @SuppressWarnings("JdkObsolete") private Date extractExpiresDateFromCacheControl(String lastModified, String cacheControl, String expires, String etag, String url, String date, final String maxAge, Date defaultExpiresDate) { @@ -312,6 +314,7 @@ private Date extractExpiresDateFromCacheControl(String lastModified, return defaultExpiresDate; } + @SuppressWarnings("JdkObsolete") private Date calcExpiresDate(String lastModified, String cacheControl, String expires, String etag, String url, String date) { if(!StringUtils.isEmpty(lastModified) && !StringUtils.isEmpty(date)) { @@ -500,6 +503,7 @@ public String getValue() { } + @SuppressWarnings("JdkObsolete") private boolean entryStillValid(URL url, CacheEntry entry) { log.debug("Check if entry {} is still valid for url {}", entry, url); if (entry != null && entry.getVaryHeader() == null) { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java index dd56b3cfe1a..a5c07414b75 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HC4CookieHandler.java @@ -55,6 +55,7 @@ public class HC4CookieHandler implements CookieHandler { // Needed by CookiePanel public static final String DEFAULT_POLICY_NAME = CookieSpecs.STANDARD; // NOSONAR + @SuppressWarnings("deprecation") private static final String[] AVAILABLE_POLICIES = new String[]{ DEFAULT_POLICY_NAME, CookieSpecs.STANDARD_STRICT, @@ -70,6 +71,7 @@ public class HC4CookieHandler implements CookieHandler { private final transient CookieSpec cookieSpec; private static final PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault(); + @SuppressWarnings("deprecation") private static Registry registry = RegistryBuilder.create() // case is ignored bug registry as it converts to lowerCase(Locale.US) @@ -102,6 +104,7 @@ public HC4CookieHandler(String policy) { } @Override + @SuppressWarnings("JdkObsolete") public void addCookieFromHeader(CookieManager cookieManager, boolean checkCookies, String cookieHeader, URL url) { boolean debugEnabled = log.isDebugEnabled(); @@ -237,6 +240,7 @@ List getCookiesForUrl( /** * Create an HttpClient cookie from a JMeter cookie */ + @SuppressWarnings("JdkObsolete") private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) { long exp = jmc.getExpiresMillis(); BasicClientCookie ret = new BasicClientCookie(jmc.getName(), diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java index 161bc92b153..48afef2fd30 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java @@ -276,14 +276,17 @@ public static HTTPSamplerBase createUrlFromAnchor(String parsedUrlString, URL co return sampler; } + @SuppressWarnings("JdkObsolete") public static List createURLFromForm(Node doc, URL context) { String selectName = null; + // TODO: migrate to ArrayDequeue LinkedList urlConfigs = new LinkedList<>(); recurseForm(doc, urlConfigs, context, selectName, false); return urlConfigs; } // N.B. Since the tags are extracted from an HTML Form, any values must already have been encoded + @SuppressWarnings("JdkObsolete") private static boolean recurseForm(Node tempNode, LinkedList urlConfigs, URL context, String selectName, boolean inForm) { NamedNodeMap nodeAtts = tempNode.getAttributes(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java index 3235bbd008a..ffedff91e1c 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java @@ -50,7 +50,6 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; -import org.apache.http.conn.ssl.AbstractVerifier; import org.apache.jmeter.assertions.Assertion; import org.apache.jmeter.assertions.ResponseAssertion; import org.apache.jmeter.assertions.gui.AssertionGui; @@ -1594,11 +1593,12 @@ private void initDynamicKeyStore() throws IOException, GeneralSecurityException } } + @SuppressWarnings("deprecation") private boolean isValid(String subject) { String[] parts = subject.split("\\."); return !parts[0].endsWith("*") // not a wildcard || parts.length >= 3 - && AbstractVerifier.acceptableCountryWildcard(subject); + && org.apache.http.conn.ssl.AbstractVerifier.acceptableCountryWildcard(subject); } // This should only be called for a specific host diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java index 02f102e1486..cd433a0010e 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPFileImpl.java @@ -96,7 +96,7 @@ protected HTTPSampleResult sample(URL url, String method, } catch (IOException e) { return errorResult(e, res); } finally { - IOUtils.closeQuietly(is); + IOUtils.closeQuietly(is, null); } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index 4824ed6a700..bd73d4e5741 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -353,7 +353,9 @@ public void process(HttpRequest request, HttpContext context) throws HttpExcepti */ private void fillAuthCache(HttpHost targetHost, Authorization authorization, AuthCache authCache, AuthScope authScope) { - if(authorization.getMechanism() == Mechanism.BASIC_DIGEST || // NOSONAR + @SuppressWarnings("deprecation") + Mechanism basicDigest = Mechanism.BASIC_DIGEST; + if(authorization.getMechanism() == basicDigest || authorization.getMechanism() == Mechanism.BASIC) { BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 920be9e31fb..34dfd00469c 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -18,6 +18,7 @@ package org.apache.jmeter.protocol.http.sampler; import java.io.ByteArrayOutputStream; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -567,7 +568,7 @@ public void setDoMultipartPost(boolean value) { } /** - * @deprecated use {@link HTTPSamplerBase#getDoMultipartPost()} + * @deprecated use {@link HTTPSamplerBase#getDoMultipart()} * @return flag whether multiparts should be used */ @Deprecated @@ -1907,7 +1908,7 @@ public void testIterationStart(LoopIterationEvent event) { public byte[] readResponse(SampleResult sampleResult, InputStream in, long length) throws IOException { OutputStream w = null; - try { // NOSONAR No try with resource as performance is critical here + try (Closeable ignore = in) { // NOSONAR No try with resource as performance is critical here byte[] readBuffer = new byte[8192]; // 8kB is the (max) size to have the latency ('the first packet') int bufferSize = 32;// Enough for MD5 @@ -1978,8 +1979,7 @@ public byte[] readResponse(SampleResult sampleResult, InputStream in, long lengt } } finally { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(w); + IOUtils.closeQuietly(w, null); } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPResultConverter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPResultConverter.java index 99c3fbb530d..2e759b83b53 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPResultConverter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPResultConverter.java @@ -80,7 +80,7 @@ private void saveSamplerData(HierarchicalStreamWriter writer, MarshallingContext writeString(writer, TAG_REDIRECT_LOCATION, res.getRedirectLocation()); } if (save.saveUrl()) { - writeItem(res.getURL(), context, writer); + writeCompleteItem(res.getURL(), context, writer); } } @@ -91,7 +91,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co retrieveAttributes(reader, context, res); while (reader.hasMoreChildren()) { reader.moveDown(); - Object subItem = readItem(reader, context, res); + Object subItem = readBareItem(reader, context, res); if (!retrieveItem(reader, context, res, subItem)) { retrieveHTTPItem(reader, res, subItem); } diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java index f88e81845d1..7d9a39689b7 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestAuthorization.java @@ -28,7 +28,7 @@ public class TestAuthorization { @Test public void testToBasicHeader() { Authorization basicAuthorization = new Authorization("http://example.com", "foo", "bar", null, "Test Realm", - Mechanism.BASIC_DIGEST); + Mechanism.BASIC); assertThat(basicAuthorization.toBasicHeader(), CoreMatchers.is("Basic Zm9vOmJhcg==")); } diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java index 1c9f35872ca..2c73ceafc23 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java @@ -205,6 +205,7 @@ private String asString(Header[] headers) { return result.toString(); } + @SuppressWarnings("deprecation") private void testCacheVary(String vary, Header[] origHeaders, Header[] differentHeaders) throws Exception { this.cacheManager.setUseExpires(true); this.cacheManager.testIterationStart(null); @@ -335,17 +336,20 @@ public void testCacheHttpClientBug51932() throws Exception { assertInvalidEntry(); } + @SuppressWarnings("deprecation") private void assertInvalidEntry() throws Exception { CacheEntry cachedEntry = getThreadCacheEntry(LOCAL_HOST); assertNotNull(getThreadCacheEntry(LOCAL_HOST), "Should find entry"); assertFalse(this.cacheManager.inCache(url), "Should not find valid entry. Found: " + cachedEntry + " at " + System.currentTimeMillis()); } + @SuppressWarnings("deprecation") private void assertValidEntry() throws Exception { assertNotNull(getThreadCacheEntry(LOCAL_HOST), "Should find entry"); assertTrue(this.cacheManager.inCache(url), "Should find valid entry"); } + @SuppressWarnings("deprecation") private void assertNoSuchEntry() throws Exception { assertNull(getThreadCacheEntry(LOCAL_HOST), "Should not find entry"); assertFalse(this.cacheManager.inCache(url), "Should not find valid entry"); diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerHC4.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerHC4.java index 2c63ff1d3f3..0cefd3b96e6 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerHC4.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerHC4.java @@ -258,6 +258,7 @@ protected void checkRequestHeader(String requestHeader, String expectedValue) { } @Test + @SuppressWarnings("deprecation") public void testBug61321() throws Exception { this.cacheManager.setUseExpires(false); this.cacheManager.testIterationStart(null); diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java index 3a1c4a7adb4..2c2c2d9ec74 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java @@ -83,7 +83,7 @@ public void testRepeatedArguments() throws Exception { + postBody; s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); assertEquals(contentEncoding, s.getContentEncoding()); // Check arguments arguments = s.getArguments(); @@ -112,7 +112,7 @@ public void testRepeatedArguments() throws Exception { + postBody; s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); assertEquals(contentEncoding, s.getContentEncoding()); // Check arguments // We should have one argument, with the value equal to the post body @@ -134,7 +134,7 @@ public void testRepeatedArguments() throws Exception { // request is "sent" using that encoding s = getSamplerForRequest(null, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); assertEquals(contentEncoding, s.getContentEncoding()); // Check arguments // We should have one argument, with the value equal to the post body @@ -180,7 +180,7 @@ public void testRepeatedArguments() throws Exception { // request is "sent" using that encoding s = getSamplerForRequest(null, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); // TODO Should this be OK ? //assertEquals(contentEncoding, s.getContentEncoding()); // Check arguments @@ -259,7 +259,7 @@ private void testEncodedArguments(String url) throws Exception { assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(queryString, s.getQueryString()); assertEquals(contentEncoding, s.getContentEncoding()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); // Check arguments arguments = s.getArguments(); @@ -283,7 +283,7 @@ private void testEncodedArguments(String url) throws Exception { expectedQueryString = "abc%3FSPACE=a+b&space=a+b&query=What%3F"; assertEquals(expectedQueryString, s.getQueryString()); assertEquals(contentEncoding, s.getContentEncoding()); - assertFalse(s.getDoMultipartPost()); + assertFalse(s.getDoMultipart()); // Check arguments arguments = s.getArguments(); @@ -453,7 +453,7 @@ public void testPostMultipartFormData() throws Exception { HTTPSamplerBase s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(contentEncoding, s.getContentEncoding()); - assertTrue(s.getDoMultipartPost()); + assertTrue(s.getDoMultipart()); // Check arguments Arguments arguments = s.getArguments(); @@ -473,7 +473,7 @@ public void testPostMultipartFormData() throws Exception { s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(contentEncoding, s.getContentEncoding()); - assertTrue(s.getDoMultipartPost()); + assertTrue(s.getDoMultipart()); // Check arguments arguments = s.getArguments(); @@ -493,7 +493,7 @@ public void testPostMultipartFormData() throws Exception { s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(contentEncoding, s.getContentEncoding()); - assertTrue(s.getDoMultipartPost()); + assertTrue(s.getDoMultipart()); // Check arguments arguments = s.getArguments(); @@ -513,7 +513,7 @@ public void testPostMultipartFormData() throws Exception { s = getSamplerForRequest(url, testPostRequest, contentEncoding); assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(contentEncoding, s.getContentEncoding()); - assertTrue(s.getDoMultipartPost()); + assertTrue(s.getDoMultipart()); // Check arguments arguments = s.getArguments(); @@ -571,7 +571,7 @@ public void testPostMultipartFileUpload() throws Exception { assertEquals(HTTPConstants.POST, s.getMethod()); assertEquals(contentEncoding, s.getContentEncoding()); assertEquals("", s.getQueryString()); - assertTrue(s.getDoMultipartPost()); + assertTrue(s.getDoMultipart()); // Check arguments Arguments arguments = s.getArguments(); diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java index 4b736556300..0d8534bebb3 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/sampler/JavaSampler.java @@ -322,6 +322,7 @@ class ErrorSamplerClient extends AbstractJavaSamplerClient { * @see JavaSamplerClient#runTest(JavaSamplerContext) */ @Override + @SuppressWarnings("ThreadPriorityCheck") public SampleResult runTest(JavaSamplerContext p_context) { if (log.isDebugEnabled()) { log.debug("{}\trunTest", whoAmI()); diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java index 50f4535faf1..1abd0eed12a 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java @@ -230,7 +230,7 @@ private BasicDataSource initPool(String maxPool) { int poolSize = Integer.parseInt(maxPool); dataSource.setMinIdle(0); dataSource.setInitialSize(poolSize); - dataSource.setEnableAutoCommitOnReturn(false); + dataSource.setAutoCommitOnReturn(false); if(StringUtils.isNotEmpty(initQuery)) { String[] sqls = initQuery.split("\n"); dataSource.setConnectionInitSqls(Arrays.asList(sqls)); diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/Utils.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/Utils.java index 54fda43f6db..2ae3eddb089 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/Utils.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/Utils.java @@ -99,6 +99,7 @@ public static String messageProperties(Message msg){ return messageProperties(new StringBuilder(), msg).toString(); } + @SuppressWarnings("JdkObsolete") public static StringBuilder messageProperties(StringBuilder sb, Message msg){ requestHeaders(sb, msg); sb.append("Properties:\n"); @@ -163,6 +164,7 @@ public static Destination lookupDestination(Context context, String name) throws * @throws NamingException * if a naming problem occurs while getting the environment */ + @SuppressWarnings("JdkObsolete") public static String getFromEnvironment(Context context, String key) throws NamingException { try { Hashtable env = context.getEnvironment(); diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java index b34918c43f7..381b155ff1e 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/control/gui/JMSSamplerGui.java @@ -137,7 +137,9 @@ private void transfer(JMSSampler element) { element.setReceiveQueue(receiveQueue.getText()); element.setProperty(JMSSampler.JMS_COMMUNICATION_STYLE, jmsCommunicationStyle.getSelectedIndex()); - element.removeProperty(JMSSampler.IS_ONE_WAY); + @SuppressWarnings("deprecation") + String isOneWay = JMSSampler.IS_ONE_WAY; + element.removeProperty(isOneWay); element.setNonPersistent(useNonPersistentDelivery.isSelected()); element.setUseReqMsgIdAsCorrelId(useReqMsgIdAsCorrelId.isSelected()); element.setUseResMsgIdAsCorrelId(useResMsgIdAsCorrelId.isSelected()); @@ -183,7 +185,9 @@ public void configure(TestElement el) { queueConnectionFactory.setText(sampler.getQueueConnectionFactory()); sendQueue.setText(sampler.getSendQueue()); receiveQueue.setText(sampler.getReceiveQueue()); - JMeterProperty oneWay = el.getProperty(JMSSampler.IS_ONE_WAY); // NOSONAR + @SuppressWarnings("deprecation") + String isOneWay = JMSSampler.IS_ONE_WAY; + JMeterProperty oneWay = el.getProperty(isOneWay); // NOSONAR if(oneWay instanceof NullProperty) { jmsCommunicationStyle.setSelectedIndex(el.getPropertyAsInt(JMSSampler.JMS_COMMUNICATION_STYLE)); } else { diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java index 652aef7de08..8cf7c1cc0c7 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java @@ -284,7 +284,7 @@ private void handleError(SampleResult result, Exception e, boolean checkForRecon String errorCode = Optional.ofNullable(jms.getErrorCode()).orElse(""); if (checkForReconnect && publisher != null && getIsReconnectErrorCode().test(errorCode)) { ClientPool.removeClient(publisher); - IOUtils.closeQuietly(publisher); + IOUtils.closeQuietly(publisher, null); publisher = null; } diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java index 6043f02d56e..21f1eecb826 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java @@ -256,7 +256,7 @@ private void handleErrorAndAddTemporize(boolean reconnect) { * */ private void cleanup() { - IOUtils.closeQuietly(SUBSCRIBER); + IOUtils.closeQuietly(SUBSCRIBER, null); } /** diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java index 60fc1a5f554..5566f9f5645 100644 --- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java +++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java @@ -188,7 +188,7 @@ private boolean executeMessage(SampleResult result, SendMailCommand sendMailCmd, private long calculateMessageSize(Message message) throws IOException, MessagingException { if (getPropertyAsBoolean(MESSAGE_SIZE_STATS)) { // calculate message size - CountingOutputStream cs = new CountingOutputStream(new NullOutputStream()); + CountingOutputStream cs = new CountingOutputStream(NullOutputStream.NULL_OUTPUT_STREAM); message.writeTo(cs); return cs.getByteCount(); } else { diff --git a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java index 5b1024feb76..ac8e560fa37 100644 --- a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java +++ b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/AbstractTCPClient.java @@ -84,6 +84,7 @@ public void setCharset(String charset) { * @see org.apache.jmeter.protocol.tcp.sampler.TCPClient#read(java.io.InputStream, org.apache.jmeter.samplers.SampleResult) */ @Override + @SuppressWarnings("deprecation") public String read(InputStream is, SampleResult sampleResult) throws ReadException { return read(is); } diff --git a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java index 5213ede914f..2971aab578a 100644 --- a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java +++ b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImpl.java @@ -22,7 +22,6 @@ import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.util.JOrphanUtils; @@ -135,7 +134,6 @@ public String read(InputStream is, SampleResult sampleResult) throws ReadExcepti } } - IOUtils.closeQuietly(w); // For completeness final String hexString = JOrphanUtils.baToHexString(w.toByteArray()); if(log.isDebugEnabled()) { log.debug("Read: " + w.size() + "\n" + hexString); From 77d5d1bc92dd70555ed689bd0ec5f25685f68d66 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:27:22 +0300 Subject: [PATCH 09/40] Remove excessive parenthesis --- .../extractor/json/render/AbstractRenderAsJsonRenderer.java | 2 +- .../org/apache/jmeter/visualizers/RespTimeGraphChart.java | 2 +- .../apache/jmeter/visualizers/RespTimeGraphVisualizer.java | 2 +- .../org/apache/jmeter/visualizers/SearchTextExtension.java | 2 +- .../org/apache/jmeter/visualizers/StatGraphVisualizer.java | 2 +- .../apache/jmeter/visualizers/ViewResultsFullVisualizer.java | 4 ++-- .../backend/influxdb/InfluxdbBackendListenerClient.java | 2 +- .../src/main/java/org/apache/jmeter/engine/TreeCloner.java | 2 +- .../main/java/org/apache/jmeter/gui/util/IconToolbarBean.java | 2 +- .../src/main/java/org/apache/jmeter/threads/ThreadGroup.java | 2 +- .../main/java/org/apache/jmeter/util/JSR223TestElement.java | 4 ++-- .../main/java/org/apache/jmeter/functions/LogFunction.java | 2 +- .../main/java/org/apache/jmeter/functions/RandomString.java | 4 ++-- .../apache/jmeter/protocol/http/parser/HtmlParsingUtils.java | 2 +- .../jmeter/protocol/http/proxy/DefaultSamplerCreator.java | 2 +- .../apache/jmeter/protocol/http/proxy/FormCharSetFinder.java | 2 +- .../java/org/apache/jmeter/protocol/http/proxy/Proxy.java | 2 +- .../org/apache/jmeter/protocol/http/sampler/AjpSampler.java | 2 +- .../org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java | 2 +- .../org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java | 2 +- .../java/org/apache/jmeter/protocol/java/test/JavaTest.java | 2 +- .../java/org/apache/jmeter/protocol/java/test/SleepTest.java | 2 +- .../apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java | 4 ++-- .../jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java | 4 ++-- .../apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java | 2 +- 25 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/AbstractRenderAsJsonRenderer.java b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/AbstractRenderAsJsonRenderer.java index 73a3d77b6c2..38f41a02a9f 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/AbstractRenderAsJsonRenderer.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/AbstractRenderAsJsonRenderer.java @@ -92,7 +92,7 @@ public void init() { @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); - if ((sampleResult != null) && (TESTER_COMMAND.equals(command))) { + if ((sampleResult != null) && TESTER_COMMAND.equals(command)) { String response = jsonDataField.getText(); executeTester(response); } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java index f1216f787e2..02ab8f09f6d 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphChart.java @@ -403,7 +403,7 @@ private double findMax(double[][] datas) { double max = 0; for (double[] data : datas) { for (final double value : data) { - if ((!Double.isNaN(value)) && (value > max)) { + if (!Double.isNaN(value) && (value > max)) { max = value; } } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java index 59ad93f4bb8..405e504212f 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java @@ -295,7 +295,7 @@ public void add(final SampleResult sampleResult) { if (samplerSelection.isSelected() && pattern != null) { matcher = pattern.matcher(sampleLabel); } - if ((matcher == null) || (matcher.find())) { + if (matcher == null || matcher.find()) { final long startTimeMS = sampleResult.getStartTime(); final long startTimeInterval = startTimeMS / intervalValue; JMeterUtils.runSafe(false, () -> { diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/SearchTextExtension.java b/src/components/src/main/java/org/apache/jmeter/visualizers/SearchTextExtension.java index 15329ca7d28..fc7ce416ac1 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/SearchTextExtension.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/SearchTextExtension.java @@ -282,7 +282,7 @@ public boolean executeAndShowTextFind(Pattern pattern) { String body = contentDoc.getText(lastPosition, contentDoc.getLength() - lastPosition); matcher = pattern.matcher(body); - if ((matcher != null) && (matcher.find())) { + if (matcher.find()) { selection.removeAllHighlights(); selection.addHighlight(lastPosition + matcher.start(), lastPosition + matcher.end(), painter); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java index 7ce6d379c5e..7a7cf73bbab 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java @@ -477,7 +477,7 @@ public void add(final SampleResult res) { if (columnSelection.isSelected() && pattern != null) { matcher = pattern.matcher(sampleLabel); } - if ((matcher == null) || (matcher.find())) { + if (matcher == null || matcher.find()) { SamplingStatCalculator row = tableRows.computeIfAbsent(sampleLabel, label -> { SamplingStatCalculator newRow = new SamplingStatCalculator(label); newRows.addLast(newRow); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java index 48cf1de43ac..fe49760ffc0 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java @@ -403,7 +403,7 @@ private void valueChanged(TreeSelectionEvent e, boolean forceRendering) { * @return true if sampleResult is text or has empty content type */ protected static boolean isTextDataType(SampleResult sampleResult) { - return (SampleResult.TEXT).equals(sampleResult.getDataType()) + return SampleResult.TEXT.equals(sampleResult.getDataType()) || StringUtils.isEmpty(sampleResult.getDataType()); } @@ -571,7 +571,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean failure = true; Object userObject = ((DefaultMutableTreeNode) value).getUserObject(); if (userObject instanceof SampleResult) { - failure = !(((SampleResult) userObject).isSuccessful()); + failure = !((SampleResult) userObject).isSuccessful(); } else if (userObject instanceof AssertionResult) { AssertionResult assertion = (AssertionResult) userObject; failure = assertion.isError() || assertion.isFailure(); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java index 0c61e9748bc..f46c38324c4 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/InfluxdbBackendListenerClient.java @@ -298,7 +298,7 @@ public void handleSampleResults(List sampleResults, BackendListene for (SampleResult sampleResult : sampleResults) { userMetrics.add(sampleResult); Matcher matcher = samplersToFilter.matcher(sampleResult.getSampleLabel()); - if (!summaryOnly && (matcher.find())) { + if (!summaryOnly && matcher.find()) { SamplerMetric samplerMetric = getSamplerMetricInfluxdb(sampleResult.getSampleLabel()); samplerMetric.add(sampleResult); } diff --git a/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java b/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java index 19b236b514d..fddc404ab1c 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/TreeCloner.java @@ -71,7 +71,7 @@ public final void addNode(Object node, HashTree subTree) { protected Object addNodeToTree(Object node) { if ( (node instanceof TestElement) // Check can cast for clone // Don't clone NoThreadClone unless honourNoThreadClone == false - && (!(honourNoThreadClone && (node instanceof NoThreadClone))) + && !(honourNoThreadClone && node instanceof NoThreadClone) ) { Object newNode = ((TestElement) node).clone(); newTree.add(objects, newNode); diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/IconToolbarBean.java b/src/core/src/main/java/org/apache/jmeter/gui/util/IconToolbarBean.java index 009f5aa378c..ebaf61b3876 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/IconToolbarBean.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/IconToolbarBean.java @@ -81,7 +81,7 @@ public final class IconToolbarBean { public String getActionNameResolve() { final String aName; try { - aName = (String) (ActionNames.class.getField(this.actionName).get(null)); + aName = (String) ActionNames.class.getField(this.actionName).get(null); } catch (Exception e) { log.warn("Toolbar icon Action names error: {}, use unknown action.", this.actionName); //$NON-NLS-1$ return this.actionName; // return unknown action names for display error msg diff --git a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java index 8a376c7b0a2..d7d273218bc 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java @@ -198,7 +198,7 @@ private void scheduleThread(JMeterThread thread, long now) { // set the endtime for the Thread if (getDuration() > 0) {// Duration is in seconds - thread.setEndTime(getDuration() * 1000 + (thread.getStartTime())); + thread.setEndTime(getDuration() * 1000 + thread.getStartTime()); } else { throw new JMeterStopTestException("Invalid duration " + getDuration() + " set in Thread Group:" + getName()); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java index 9a5682455f4..e0f693c34c5 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java @@ -169,7 +169,7 @@ protected Object processFileOrScript(ScriptEngine scriptEngine, final Bindings p // Hack: bsh-2.0b5.jar BshScriptEngine implements Compilable but throws // "java.lang.Error: unimplemented" boolean supportsCompilable = scriptEngine instanceof Compilable - && !("bsh.engine.BshScriptEngine".equals(scriptEngine.getClass().getName())); // NOSONAR // $NON-NLS-1$ + && !"bsh.engine.BshScriptEngine".equals(scriptEngine.getClass().getName()); // NOSONAR // $NON-NLS-1$ try { if (!StringUtils.isEmpty(getFilename())) { if (scriptFile.exists() && scriptFile.canRead()) { @@ -245,7 +245,7 @@ public boolean compile() String lang = getScriptLanguageWithDefault(); ScriptEngine scriptEngine = getInstance().getEngineByName(lang); boolean supportsCompilable = scriptEngine instanceof Compilable - && !("bsh.engine.BshScriptEngine".equals(scriptEngine.getClass().getName())); // NOSONAR // $NON-NLS-1$ + && !"bsh.engine.BshScriptEngine".equals(scriptEngine.getClass().getName()); // NOSONAR // $NON-NLS-1$ if(!supportsCompilable) { return true; } diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java index 33f736a42e9..6ea2d48d04b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/LogFunction.java @@ -157,7 +157,7 @@ static synchronized void logDetails(Logger logger, String stringToLog, String pr } final String threadName = Thread.currentThread().getName(); - final String separator = (comment.isEmpty()) ? DEFAULT_SEPARATOR : comment; + final String separator = comment.isEmpty() ? DEFAULT_SEPARATOR : comment; switch (prioLevel) { case ERROR: diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java b/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java index fd39001a15e..1dd00483928 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/RandomString.java @@ -75,7 +75,7 @@ public String execute(SampleResult previousResult, Sampler currentSampler) String charsToUse = null;//means no restriction if (values.length >= CHARS) { - charsToUse = (values[CHARS - 1]).execute().trim(); + charsToUse = values[CHARS - 1].execute().trim(); if (charsToUse.length() <= 0) { // empty chars, return to null charsToUse = null; } @@ -83,7 +83,7 @@ public String execute(SampleResult previousResult, Sampler currentSampler) String myName = "";//$NON-NLS-1$ if (values.length >= PARAM_NAME) { - myName = (values[PARAM_NAME - 1]).execute().trim(); + myName = values[PARAM_NAME - 1].execute().trim(); } String myValue = null; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java index 48afef2fd30..2b3fbb8fa17 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java @@ -106,7 +106,7 @@ public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase c Argument item = (Argument) argument.getObjectValue(); final String name = item.getName(); if (!query.contains(name + "=")) { // $NON-NLS-1$ - if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) { + if (!matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK))) { return false; } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java index 5e6e588d491..f91f01aa425 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java @@ -205,7 +205,7 @@ protected void computeFromPostBody(HTTPSamplerBase sampler, // If it was a HTTP GET request, then all parameters in the URL // has been handled by the sampler.setPath above, so we just need // to do parse the rest of the request if it is not a GET request - if((!HTTPConstants.CONNECT.equals(request.getMethod())) && (!HTTPConstants.GET.equals(request.getMethod()))) { + if(!HTTPConstants.CONNECT.equals(request.getMethod()) && !HTTPConstants.GET.equals(request.getMethod())) { // Check if it was a multipart http post request final String contentType = request.getContentType(); MultipartUrlConfig urlConfig = request.getMultipartConfig(contentType); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java index edf7d95ff64..84b595a227b 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/FormCharSetFinder.java @@ -56,7 +56,7 @@ public void addFormActionsAndCharSet(String html, Map formEncodi Elements forms = document.select("form"); for (Element element : forms) { String action = element.attr("action"); - if( !(StringUtils.isEmpty(action)) ) { + if (!StringUtils.isEmpty(action)) { // We use the page encoding where the form resides, as the // default encoding for the form String formCharSet = pageEncoding; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java index 37c1f471cb4..21a228834f2 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java @@ -185,7 +185,7 @@ public void run() { // Use with SSL connection OutputStream outStreamClient = clientSocket.getOutputStream(); - if ((request.getMethod().startsWith(HTTPConstants.CONNECT)) && (outStreamClient != null)) { + if (request.getMethod().startsWith(HTTPConstants.CONNECT) && (outStreamClient != null)) { log.debug("{} Method CONNECT => SSL", port); // write a OK response to browser, to engage SSL exchange outStreamClient.write( diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java index 1c611e93dc3..8233f9f8e99 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java @@ -326,7 +326,7 @@ private String setConnectionCookies(URL url, CookieManager cookies) { if(cookies != null) { cookieHeader = cookies.getCookieHeaderForURL(url); for (JMeterProperty jMeterProperty : cookies.getCookies()) { - Cookie cookie = (Cookie)(jMeterProperty.getObjectValue()); + Cookie cookie = (Cookie) jMeterProperty.getObjectValue(); setInt(0xA009); // Cookie setString(cookie.getName()+"="+cookie.getValue());//$NON-NLS-1$ } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index bd73d4e5741..9b8715e4af2 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -1464,7 +1464,7 @@ private String getAllHeadersExceptCookie(HttpRequest method) { private String getOnlyCookieFromHeaders(HttpRequest method) { String cookieHeader= getFromHeadersMatchingPredicate(method, ONLY_COOKIE).trim(); if(!cookieHeader.isEmpty()) { - return cookieHeader.substring((HTTPConstants.HEADER_COOKIE_IN_REQUEST).length(), cookieHeader.length()).trim(); + return cookieHeader.substring(HTTPConstants.HEADER_COOKIE_IN_REQUEST.length()).trim(); } return ""; } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java index e1c798cf5f6..c2afb32e220 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java @@ -397,7 +397,7 @@ private void setConnectionHeaders(HttpURLConnection conn, URL u, private String getOnlyCookieFromHeaders(HttpURLConnection conn, Map securityHeaders) { String cookieHeader= getFromConnectionHeaders(conn, securityHeaders, ONLY_COOKIE, false).trim(); if(!cookieHeader.isEmpty()) { - return cookieHeader.substring((HTTPConstants.HEADER_COOKIE_IN_REQUEST).length(), cookieHeader.length()).trim(); + return cookieHeader.substring(HTTPConstants.HEADER_COOKIE_IN_REQUEST.length()).trim(); } return ""; } diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/JavaTest.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/JavaTest.java index 8b51aaf661a..2aaa3b7095d 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/JavaTest.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/JavaTest.java @@ -92,7 +92,7 @@ public class JavaTest extends AbstractJavaSamplerClient implements Serializable, public static final long DEFAULT_SLEEP_MASK = 0xff; /** Formatted string representation of the default SleepMask. */ - private static final String DEFAULT_MASK_STRING = "0x" + (Long.toHexString(DEFAULT_SLEEP_MASK)).toUpperCase(java.util.Locale.ENGLISH); + private static final String DEFAULT_MASK_STRING = "0x" + Long.toHexString(DEFAULT_SLEEP_MASK).toUpperCase(java.util.Locale.ENGLISH); /** The name used to store the SleepMask parameter. */ private static final String MASK_NAME = "Sleep_Mask"; diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/SleepTest.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/SleepTest.java index 3c3efd62664..363899c21e1 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/SleepTest.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/test/SleepTest.java @@ -188,7 +188,7 @@ public SampleResult runTest(JavaSamplerContext context) { public Arguments getDefaultParameters() { Arguments params = new Arguments(); params.addArgument("SleepTime", String.valueOf(DEFAULT_SLEEP_TIME)); - params.addArgument("SleepMask", "0x" + (Long.toHexString(DEFAULT_SLEEP_MASK)).toUpperCase(java.util.Locale.ENGLISH)); + params.addArgument("SleepMask", "0x" + Long.toHexString(DEFAULT_SLEEP_MASK).toUpperCase(java.util.Locale.ENGLISH)); return params; } diff --git a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java index 1253a0ea456..b16ba8f4c8e 100644 --- a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java +++ b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java @@ -127,7 +127,7 @@ public void configure(TestElement element) { servername.setText(element.getPropertyAsString(LDAPSampler.SERVERNAME)); port.setText(element.getPropertyAsString(LDAPSampler.PORT)); rootdn.setText(element.getPropertyAsString(LDAPSampler.ROOTDN)); - CardLayout cl = (CardLayout) (cards.getLayout()); + CardLayout cl = (CardLayout) cards.getLayout(); final String testType = element.getPropertyAsString(LDAPSampler.TEST); if (testType.equals(LDAPSampler.ADD)) { addTest.setSelected(true); @@ -232,7 +232,7 @@ public void clearGui() { */ @Override public void itemStateChanged(ItemEvent ie) { - CardLayout cl = (CardLayout) (cards.getLayout()); + CardLayout cl = (CardLayout) cards.getLayout(); if (userDefined.isSelected()) { if (addTest.isSelected()) { cl.show(cards, "Add"); diff --git a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java index e3f1804bfcb..e216c493662 100644 --- a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java +++ b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/config/gui/LdapExtConfigGui.java @@ -218,7 +218,7 @@ public void configure(TestElement element) { comparefilt.setText(element.getPropertyAsString(LDAPExtSampler.COMPAREFILT)); modddn.setText(element.getPropertyAsString(LDAPExtSampler.MODDDN)); newdn.setText(element.getPropertyAsString(LDAPExtSampler.NEWDN)); - CardLayout cl = (CardLayout) (cards.getLayout()); + CardLayout cl = (CardLayout) cards.getLayout(); final String testType = element.getPropertyAsString(LDAPExtSampler.TEST); if (testType.equals(LDAPExtSampler.UNBIND)) { unbind.setSelected(true); @@ -383,7 +383,7 @@ public void clearGui() { **************************************************************************/ @Override public void itemStateChanged(ItemEvent ie) { - CardLayout cl = (CardLayout) (cards.getLayout()); + CardLayout cl = (CardLayout) cards.getLayout(); if (addTest.isSelected()) { cl.show(cards, CARDS_ADD); } else if (deleteTest.isSelected()) { diff --git a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java index a2e87fe7435..3531b8b6ef1 100644 --- a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java +++ b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java @@ -536,7 +536,7 @@ private ModificationItem[] getUserModAttributes() { while (iter.hasNext()) { BasicAttribute attr; LDAPArgument item = (LDAPArgument) iter.next().getObjectValue(); - if ((item.getValue()).length()==0) { + if (item.getValue().length() == 0) { attr = new BasicAttribute(item.getName()); } else { attr = getBasicAttribute(item.getName(), item.getValue()); From 73b925c5b779a84ea2fab2670c9116d31432cd7f Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 15:27:52 +0300 Subject: [PATCH 10/40] Avoid unsafe reflection cast --- .../org/apache/jmeter/visualizers/RequestPanel.java | 4 +++- .../visualizers/ViewResultsFullVisualizer.java | 4 +++- .../visualizers/backend/BackendListenerGui.java | 6 ++++-- .../apache/jmeter/engine/util/CompoundVariable.java | 4 +++- .../java/org/apache/jmeter/save/SaveService.java | 5 +++-- .../protocol/http/sampler/AccessLogSampler.java | 6 ++++-- .../protocol/java/config/gui/JavaConfigGui.java | 12 ++++++++---- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java index 0c810554e12..54ccb5dd9a3 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RequestPanel.java @@ -63,7 +63,9 @@ public RequestPanel() { for (String clazz : classesToAdd) { try { // Instantiate requestview classes - final RequestView requestView = (RequestView) Class.forName(clazz).getDeclaredConstructor().newInstance(); + final RequestView requestView = Class.forName(clazz) + .asSubclass(RequestView.class) + .getDeclaredConstructor().newInstance(); if (rawTab.equals(requestView.getLabel())) { rawObject = requestView; // use later } else { diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java index fe49760ffc0..191716903e7 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java @@ -460,7 +460,9 @@ private Component createComboRender() { for (String clazz : classesToAdd) { try { // Instantiate render classes - final ResultRenderer renderer = (ResultRenderer) Class.forName(clazz).getDeclaredConstructor().newInstance(); + final ResultRenderer renderer = Class.forName(clazz) + .asSubclass(ResultRenderer.class) + .getDeclaredConstructor().newInstance(); if (defaultRenderer.equals(clazz)) { defaultObject=renderer; } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListenerGui.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListenerGui.java index 43a419b829e..f1714269094 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListenerGui.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListenerGui.java @@ -236,8 +236,10 @@ private Arguments extractDefaultArguments(BackendListenerClient client, Map classes = ClassFinder.findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { Function.class }, true, contain, notContain); for (String clazzName : classes) { - Function tempFunc = (Function) Class.forName(clazzName).getDeclaredConstructor().newInstance(); + Function tempFunc = Class.forName(clazzName) + .asSubclass(Function.class) + .getDeclaredConstructor().newInstance(); String referenceKey = tempFunc.getReferenceKey(); if (referenceKey.length() > 0) { // ignore self functions.put(referenceKey, tempFunc.getClass()); diff --git a/src/core/src/main/java/org/apache/jmeter/save/SaveService.java b/src/core/src/main/java/org/apache/jmeter/save/SaveService.java index 2955c38cba8..3dad44fd7c3 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/SaveService.java +++ b/src/core/src/main/java/org/apache/jmeter/save/SaveService.java @@ -280,10 +280,11 @@ private static void registerConverter(String key, XStream jmxsaver, boolean useM throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { + final Class clazz = Class.forName(key).asSubclass(Converter.class); if (useMapper){ - jmxsaver.registerConverter((Converter) Class.forName(key).getConstructor(Mapper.class).newInstance(jmxsaver.getMapper())); + jmxsaver.registerConverter(clazz.getConstructor(Mapper.class).newInstance(jmxsaver.getMapper())); } else { - jmxsaver.registerConverter((Converter) Class.forName(key).getDeclaredConstructor().newInstance()); + jmxsaver.registerConverter(clazz.getDeclaredConstructor().newInstance()); } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java index 43c73968fe5..b25e218f3a2 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java @@ -200,7 +200,8 @@ public void instantiateParser() { try { if (StringUtils.isNotBlank(this.getParserClassName())) { if (StringUtils.isNotBlank(this.getLogFile())) { - parser = (LogParser) Class.forName(getParserClassName()).getDeclaredConstructor().newInstance(); + parser = Class.forName(getParserClassName()) + .asSubclass(LogParser.class).getDeclaredConstructor().newInstance(); parser.setSourceFile(this.getLogFile()); parser.setFilter(filter); } else { @@ -308,7 +309,8 @@ public AccessLogSampler() { protected void initFilter() { if (filter == null && StringUtils.isNotBlank(filterClassName)) { try { - filter = (Filter) Class.forName(filterClassName).getDeclaredConstructor().newInstance(); + filter = Class.forName(filterClassName) + .asSubclass(Filter.class).getDeclaredConstructor().newInstance(); } catch (Exception e) { log.warn("Couldn't instantiate filter '{}'", filterClassName, e); } diff --git a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java index 5ea7c51c8e2..53b128ce785 100644 --- a/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java +++ b/src/protocol/java/src/main/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java @@ -187,8 +187,10 @@ public void stateChanged(ChangeEvent evt) { private void configureClassName() { String className = classNameLabeledChoice.getText().trim(); try { - JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true, - Thread.currentThread().getContextClassLoader()).getDeclaredConstructor().newInstance(); + JavaSamplerClient client = Class.forName(className, true, + Thread.currentThread().getContextClassLoader()) + .asSubclass(JavaSamplerClient.class) + .getDeclaredConstructor().newInstance(); Arguments currArgs = new Arguments(); argsPanel.modifyTestElement(currArgs); @@ -267,8 +269,10 @@ public void configure(TestElement config) { */ private boolean classOk(String className) { try { - JavaSamplerClient client = (JavaSamplerClient) Class.forName(className, true, - Thread.currentThread().getContextClassLoader()).getDeclaredConstructor().newInstance(); + JavaSamplerClient client = Class.forName(className, true, + Thread.currentThread().getContextClassLoader()) + .asSubclass(JavaSamplerClient.class) + .getDeclaredConstructor().newInstance(); // Just to use client return client != null; } catch (Exception ex) { From f5c64e17cd5b64e11bb6ad87bcc0cf9d82b2064c Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 16:42:40 +0300 Subject: [PATCH 11/40] Avoid use of Enumeration in ClassFinder --- .../apache/jorphan/reflect/ClassFinder.java | 52 ++++--------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFinder.java b/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFinder.java index bb14e0322e7..1b14005c988 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFinder.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFinder.java @@ -25,16 +25,14 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Enumeration; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.TreeSet; +import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.jorphan.util.JOrphanUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -338,37 +336,6 @@ public static List findClasses(String[] searchPathsOrJars, ClassFilter f return new ArrayList<>(listClasses); } - /** - * Fix a path: - *
      - *
    • replace "{@code .}" by current directory
    • - *
    • upcase the first character if it appears to be a drive letter
    • - *
    • trim any trailing spaces
    • - *
    • replace {@code \} by {@code /}
    • - *
    • replace {@code //} by {@code /}
    • - *
    • remove all trailing {@code /}
    • - *
    - */ - private static String fixPathEntry(String path) { - if (path == null) { - return null; - } - if (path.equals(".")) { // $NON-NLS-1$ - return System.getProperty("user.dir"); // $NON-NLS-1$ - } - String resultPath = path; - if (path.length() > 3 && path.matches("[a-z]:\\\\.*")) { // lower-case drive letter? - resultPath = path.substring(0, 1).toUpperCase(Locale.ROOT) + path.substring(1); - } - resultPath = resultPath.trim().replace('\\', '/'); // $NON-NLS-1$ // $NON-NLS-2$ - resultPath = JOrphanUtils.substitute(resultPath, "//", "/"); // $NON-NLS-1$// $NON-NLS-2$ - - while (resultPath.endsWith("/")) { // $NON-NLS-1$ - resultPath = resultPath.substring(0, resultPath.length() - 1); - } - return resultPath; - } - /** * Converts a class file from the text stored in a Jar file to a version * that can be used in Class.forName(). @@ -389,15 +356,14 @@ private static void findClassesInOnePath(File file, Set listClasses, Cla if (file.isDirectory()) { findClassesInPathsDir(file.getAbsolutePath(), file, listClasses, filter); } else if (file.exists()) { - try (ZipFile zipFile = new ZipFile(file)) { - Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()) { - String strEntry = entries.nextElement().toString(); - if (strEntry.endsWith(DOT_CLASS)) { - String fixedClassName = fixClassName(strEntry); - applyFiltering(listClasses, filter, fixedClassName); - } - } + try (ZipFile zipFile = new ZipFile(file); + Stream entries = zipFile.stream()) { + entries.filter(entry -> entry.getName().endsWith(DOT_CLASS)) + .forEach(entry -> { + String fixedClassName = fixClassName(entry.getName()); + applyFiltering(listClasses, filter, fixedClassName); + } + ); } catch (IOException e) { log.warn("Can not open the jar {}, message: {}", file.getAbsolutePath(), e.getLocalizedMessage(), e); } From e8fbfa7ed6e4dcdbb8d421745c2eaec38904b508 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 16:43:32 +0300 Subject: [PATCH 12/40] Fixup JavaDocs --- .../java/org/apache/jmeter/control/ModuleController.java | 4 ++-- .../java/org/apache/jmeter/visualizers/RenderAsXML.java | 3 ++- .../src/main/java/org/apache/jmeter/gui/GuiPackage.java | 2 +- .../org/apache/jmeter/gui/action/SearchTreeCommand.java | 2 +- .../apache/jmeter/gui/util/HeaderAsPropertyRenderer.java | 4 ++-- .../java/org/apache/jmeter/testelement/TestElement.java | 9 ++++++--- .../main/java/org/apache/jorphan/exec/KeyToolUtils.java | 5 +++-- .../main/java/org/apache/jorphan/exec/StreamCopier.java | 2 +- .../main/java/org/apache/jorphan/exec/SystemCommand.java | 3 +++ .../java/org/apache/jorphan/gui/ObjectTableModel.java | 2 ++ .../java/org/apache/jorphan/gui/ObjectTableSorter.java | 3 +++ .../src/main/java/org/apache/jorphan/io/TextFile.java | 2 ++ .../java/org/apache/jorphan/reflect/ClassFilter.java | 1 + .../main/java/org/apache/jorphan/util/JOrphanUtils.java | 2 ++ .../main/java/org/apache/jorphan/util/ThreadDumper.java | 3 +++ .../protocol/http/gui/action/ParseCurlCommandAction.java | 3 +-- .../org/apache/jmeter/protocol/jms/client/Publisher.java | 2 +- 17 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java b/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java index 243a4f10e67..d46c16ffad9 100644 --- a/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java +++ b/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java @@ -75,7 +75,7 @@ public Object clone() { } /** - * Sets the (@link JMeterTreeNode) which represents the controller which + * Sets the {@link JMeterTreeNode} which represents the controller which * this object is pointing to. Used for building the test case upon * execution. * @@ -89,7 +89,7 @@ public void setSelectedNode(JMeterTreeNode tn) { } /** - * Gets the (@link JMeterTreeNode) for the Controller + * Gets the {@link JMeterTreeNode} for the Controller * * @return JMeterTreeNode */ diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java index f34e2e4ad7d..5ae7cd077df 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java @@ -98,7 +98,8 @@ private void showRenderXMLResponse(SampleResult res) { resultsScrollPane.setViewportView(domTreePanel); } - /* (non-Javadoc) + /** + * {@inheritDoc} * @see org.apache.jmeter.visualizers.SamplerResultTab#clearData() */ @Override diff --git a/src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java b/src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java index 66f80a1608b..928b7f0f832 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java @@ -517,7 +517,7 @@ public TestElement getCurrentElement() { /** * The dirty property is a flag that indicates whether there are parts of * JMeter's test tree that the user has not saved since last modification. - * Various (@link Command actions) set this property when components are + * Various {@link org.apache.jmeter.gui.action.Command} actions set this property when components are * modified/created/saved. * * @param dirty diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/SearchTreeCommand.java b/src/core/src/main/java/org/apache/jmeter/gui/action/SearchTreeCommand.java index 08b78381376..38340271b6c 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/SearchTreeCommand.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/SearchTreeCommand.java @@ -50,7 +50,7 @@ public class SearchTreeCommand extends AbstractAction { * parent. *

    * - * @param source The source object that originated the display of the dialog + * @param event The source event that originated the display of the dialog * @return A freshly created search dialog with the parent frame that could be * found, or no parent otherwise. */ diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java b/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java index ce333ed4bf5..1f3ab5c5e6f 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/HeaderAsPropertyRenderer.java @@ -43,12 +43,12 @@ public HeaderAsPropertyRenderer() { /** * @param columnsMsgParameters ignored - * @deprecated don't use {@code columnsMgsParameters} as they are + * @deprecated don't use {@code columnsMsgParameters} as they are * not moved around when rows of the corresponding table object model * are moved. */ @Deprecated - public HeaderAsPropertyRenderer(Object[][] columnsMsgParameters) { + public HeaderAsPropertyRenderer(@Deprecated Object[][] columnsMsgParameters) { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/TestElement.java b/src/core/src/main/java/org/apache/jmeter/testelement/TestElement.java index 2922d4f92b1..e103c1ba69d 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/TestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/TestElement.java @@ -288,13 +288,14 @@ public interface TestElement extends Cloneable { void setThreadContext(JMeterContext threadContext); /** - * @return Returns the threadName. + * Returns the threadName. + * @return the threadName. */ String getThreadName(); /** - * @param threadName - * The threadName to set. + * Configures thread name. + * @param threadName the threadName to set. */ void setThreadName(String threadName); @@ -314,12 +315,14 @@ public interface TestElement extends Cloneable { String getName(); /** + * Returns name of this element. * @param name * of this element */ void setName(String name); /** + * Returns comment associated with this element. * @return comment associated with this element */ String getComment(); diff --git a/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java b/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java index 508461f2213..b7a5d34b4c5 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/exec/KeyToolUtils.java @@ -181,8 +181,8 @@ public static void genkeypair(final File keystore, String alias, final String pa } /** - * Formats arguments - * @param arguments + * Formats arguments. + * @param arguments command arguments * @return String command line */ private static String formatCommand(List arguments) { @@ -440,6 +440,7 @@ private static void keytool(String command, File keystore, String password, Stri } /** + * Returns true if {@code KeyToolUtils#KEYTOOL_PATH} is configured * @return flag whether KeyToolUtils#KEYTOOL_PATH is * configured (is not null) */ diff --git a/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java b/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java index ea7b7a56f8e..6852ce25833 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/exec/StreamCopier.java @@ -39,7 +39,7 @@ class StreamCopier extends Thread { /** * @param is {@link InputStream} * @param os {@link OutputStream} - * @throws IOException + * @throws IOException if something goes wrong */ StreamCopier(InputStream is, OutputStream os) throws IOException { this.is = is; diff --git a/src/jorphan/src/main/java/org/apache/jorphan/exec/SystemCommand.java b/src/jorphan/src/main/java/org/apache/jorphan/exec/SystemCommand.java index 1e4ad9b7a3b..1c1261f0e1a 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/exec/SystemCommand.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/exec/SystemCommand.java @@ -121,6 +121,7 @@ public SystemCommand(File directory, long timeoutMillis, int pollInterval, Map getExecutionEnvironment() { diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableModel.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableModel.java index 6009c0737fd..c5c5a670144 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableModel.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableModel.java @@ -285,6 +285,7 @@ public boolean checkFunctors(Object _value, Class caller){ } /** + * Returns Object (List of Object). * @return Object (List of Object) */ public Object getObjectList() { // used by TableEditor @@ -292,6 +293,7 @@ public Object getObjectList() { // used by TableEditor } /** + * Returns List of Object. * @return List of Object */ public List getObjectListAsList() { diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableSorter.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableSorter.java index a3add1e367a..a21893d947d 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableSorter.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/ObjectTableSorter.java @@ -97,6 +97,7 @@ public ObjectTableSorter(ObjectTableModel model) { } /** + * Returns Comparator used prior to sorted columns. * @return Comparator used prior to sorted columns. */ public Comparator getPrimaryComparator() { @@ -104,6 +105,7 @@ public Comparator getPrimaryComparator() { } /** + * Returns Comparator used on column. * @param column to be compared * @return Comparator used on column. */ @@ -112,6 +114,7 @@ public Comparator getValueComparator(int column) { } /** + * Returns Comparator if all sorted columns matches. Defaults to model index comparison. * @return Comparator if all sorted columns matches. Defaults to model index comparison. */ public Comparator getFallbackComparator() { diff --git a/src/jorphan/src/main/java/org/apache/jorphan/io/TextFile.java b/src/jorphan/src/main/java/org/apache/jorphan/io/TextFile.java index 666a9b1ab12..c5369dcf16e 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/io/TextFile.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/io/TextFile.java @@ -119,6 +119,7 @@ private Charset getCharset() { } /** + * Returns encoding being used to read and write this file. * @return Encoding being used to read and write this file. */ public String getEncoding() { @@ -126,6 +127,7 @@ public String getEncoding() { } /** + * Configures encoding to be used to read and write this file. * @param string Encoding to be used to read and write this file. */ public void setEncoding(String string) { diff --git a/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFilter.java b/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFilter.java index f5b4a6ee6dd..2c5be1d7034 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFilter.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/reflect/ClassFilter.java @@ -24,6 +24,7 @@ public interface ClassFilter { /** + * Returns true if class is included. * @param className String class name * @return true if class is included */ diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java b/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java index d4f40e2e1a2..9c4e37bb140 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/JOrphanUtils.java @@ -560,6 +560,7 @@ public static void write(byte[] data, OutputStream output) throws IOException { } /** + * Returns duration formatted with format HH:mm:ss. * @param elapsedSec long elapsed time in seconds * @return String formatted with format HH:mm:ss */ @@ -753,6 +754,7 @@ public static String unsplit(Object[] splittee, Object splitChar) { } /** + * Random alphanumeric password of a given length. * @param length Max length of password * @return String random password */ diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java b/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java index 2a7d9d016be..2c6762ee78d 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/ThreadDumper.java @@ -42,6 +42,7 @@ private ThreadDumper() { } /** + * Returns name of file containing thread dump. * @return Name of file containing thread dump * @throws Exception if file cannot be written */ @@ -50,10 +51,12 @@ public static String threadDump() throws Exception { } /** + * Returns name of file containing thread dump. * @param basedir {@link File} Base directory * @return Name of file containing thread dump * @throws Exception if file cannot we written */ + @SuppressWarnings("JdkObsolete") public static String threadDump(File basedir) throws Exception { SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd_hhmmss_SSS"); String stamp = timestampFormat.format(new Date()); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java index fa0449456e3..9e953ef932b 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java @@ -360,11 +360,10 @@ private HeaderManager createHeaderManager(Request request) { } /** - * Configures a given Cookie Manager + * Configures a given Cookie Manager. * * @param cookieManager the manager to configure * @param request to copy information about cookies from - * @returns the configured cookie manager */ private void createCookieManager(CookieManager cookieManager, Request request) { cookieManager.setProperty(TestElement.GUI_CLASS, CookiePanel.class.getName()); diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java index cae87abccd3..a578a122845 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java @@ -174,7 +174,7 @@ public MapMessage publish(Map map, String destinationName, Map + * @param properties {@code Map} * @param msg Message * @param deliveryMode * @param priority From 9c92e99b2571b053d2d146abe9d55b6174f71161 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 16:48:57 +0300 Subject: [PATCH 13/40] Make constructors of abstract classes protected rather than public --- .../src/main/java/org/apache/jmeter/timers/RandomTimer.java | 2 +- .../org/apache/jmeter/timers/gui/AbstractRandomTimerGui.java | 2 +- .../java/org/apache/jmeter/visualizers/SamplerResultTab.java | 2 +- .../org/apache/jmeter/gui/AbstractJMeterGuiComponent.java | 2 +- .../report/processor/graph/AbstractGraphValueSelector.java | 2 +- .../org/apache/jmeter/reporters/AbstractListenerElement.java | 2 +- .../java/org/apache/jmeter/samplers/AbstractSampleSender.java | 2 +- .../org/apache/jmeter/testelement/AbstractTestElement.java | 2 +- .../apache/jmeter/testelement/property/AbstractProperty.java | 4 ++-- .../org/apache/jmeter/testelement/property/MultiProperty.java | 4 ++-- .../apache/jmeter/testelement/property/NumberProperty.java | 4 ++-- .../org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java | 2 +- .../src/main/java/org/apache/jmeter/util/BSFTestElement.java | 2 +- .../java/org/apache/jmeter/util/BeanShellTestElement.java | 2 +- .../main/java/org/apache/jmeter/util/JSR223TestElement.java | 2 +- .../java/org/apache/jmeter/util/ScriptingBeanInfoSupport.java | 2 +- .../java/org/apache/jmeter/util/ScriptingTestElement.java | 2 +- .../org/apache/jmeter/visualizers/gui/AbstractVisualizer.java | 2 +- .../java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java | 4 ++-- .../org/apache/jmeter/functions/AbstractFunctionByKey.java | 2 +- .../java/org/apache/jmeter/functions/AbstractHostIPName.java | 2 +- .../java/org/apache/jorphan/gui/AbstractTreeTableModel.java | 4 ++-- .../org/apache/jmeter/protocol/http/parser/BaseParser.java | 2 +- .../jmeter/protocol/http/proxy/AbstractSamplerCreator.java | 2 +- .../apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java | 2 +- .../jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java | 2 +- .../apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java | 2 +- .../jmeter/protocol/tcp/sampler/TCPClientDecorator.java | 2 +- 28 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/timers/RandomTimer.java b/src/components/src/main/java/org/apache/jmeter/timers/RandomTimer.java index 99ab4702744..39d9991de58 100644 --- a/src/components/src/main/java/org/apache/jmeter/timers/RandomTimer.java +++ b/src/components/src/main/java/org/apache/jmeter/timers/RandomTimer.java @@ -38,7 +38,7 @@ public abstract class RandomTimer extends ConstantTimer implements ModifiableTim /** * No-arg constructor. */ - public RandomTimer() { + protected RandomTimer() { } /** diff --git a/src/components/src/main/java/org/apache/jmeter/timers/gui/AbstractRandomTimerGui.java b/src/components/src/main/java/org/apache/jmeter/timers/gui/AbstractRandomTimerGui.java index b3634dc1187..aaccc03c2ee 100644 --- a/src/components/src/main/java/org/apache/jmeter/timers/gui/AbstractRandomTimerGui.java +++ b/src/components/src/main/java/org/apache/jmeter/timers/gui/AbstractRandomTimerGui.java @@ -53,7 +53,7 @@ public abstract class AbstractRandomTimerGui extends AbstractTimerGui { /** * No-arg constructor. */ - public AbstractRandomTimerGui() { + protected AbstractRandomTimerGui() { init(); } diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java index ed2a354f1c3..50bca836a3f 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java @@ -178,7 +178,7 @@ public abstract class SamplerResultTab implements ResultRenderer { null, // Value }; - public SamplerResultTab() { + protected SamplerResultTab() { // create tables resultModel = new ObjectTableModel(COLUMNS_RESULT, RowResult.class, // The object used for each row new Functor[] { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java b/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java index 36af297b3f9..aecb70f87c7 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java @@ -88,7 +88,7 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete * setting up the Name Panel and assigning the class's static label as the * name to start. */ - public AbstractJMeterGuiComponent() { + protected AbstractJMeterGuiComponent() { namePanel = new NamePanel(); init(); } diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphValueSelector.java b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphValueSelector.java index 7986ef413ed..aa7e6a5cc58 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphValueSelector.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphValueSelector.java @@ -30,7 +30,7 @@ abstract class AbstractGraphValueSelector implements GraphValueSelector { * * @param ignoreTransactionController boolean ignore {@link SampleResult} generated by {@link TransactionController} */ - public AbstractGraphValueSelector(boolean ignoreTransactionController) { + protected AbstractGraphValueSelector(boolean ignoreTransactionController) { super(); this.ignoreTransactionController = ignoreTransactionController; } diff --git a/src/core/src/main/java/org/apache/jmeter/reporters/AbstractListenerElement.java b/src/core/src/main/java/org/apache/jmeter/reporters/AbstractListenerElement.java index fe27dd39e3f..c364cf18c43 100644 --- a/src/core/src/main/java/org/apache/jmeter/reporters/AbstractListenerElement.java +++ b/src/core/src/main/java/org/apache/jmeter/reporters/AbstractListenerElement.java @@ -32,7 +32,7 @@ public abstract class AbstractListenerElement extends AbstractTestElement { // TODO should class implement SampleListener? private transient WeakReference listener; - public AbstractListenerElement() { + protected AbstractListenerElement() { } protected final Visualizer getVisualizer() { diff --git a/src/core/src/main/java/org/apache/jmeter/samplers/AbstractSampleSender.java b/src/core/src/main/java/org/apache/jmeter/samplers/AbstractSampleSender.java index dadf186c6ca..ccc0ecf64e3 100644 --- a/src/core/src/main/java/org/apache/jmeter/samplers/AbstractSampleSender.java +++ b/src/core/src/main/java/org/apache/jmeter/samplers/AbstractSampleSender.java @@ -41,7 +41,7 @@ public boolean isClientConfigured() { /** * */ - public AbstractSampleSender() { + protected AbstractSampleSender() { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/AbstractTestElement.java b/src/core/src/main/java/org/apache/jmeter/testelement/AbstractTestElement.java index 6db4effcaee..94364f26b9b 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/AbstractTestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/AbstractTestElement.java @@ -604,7 +604,7 @@ public void setThreadName(String inthreadName) { this.threadName = inthreadName; } - public AbstractTestElement() { + protected AbstractTestElement() { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java index 163757be453..37fc659d817 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/AbstractProperty.java @@ -34,14 +34,14 @@ public abstract class AbstractProperty implements JMeterProperty { private transient boolean runningVersion = false; - public AbstractProperty(String name) { + protected AbstractProperty(String name) { if (name == null) { throw new IllegalArgumentException("Name cannot be null"); } this.name = name; } - public AbstractProperty() { + protected AbstractProperty() { this(""); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/MultiProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/MultiProperty.java index a2b853b78cc..3babeed20ec 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/MultiProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/MultiProperty.java @@ -27,11 +27,11 @@ public abstract class MultiProperty extends AbstractProperty implements Iterable { private static final long serialVersionUID = 240L; - public MultiProperty() { + protected MultiProperty() { super(); } - public MultiProperty(String name) { + protected MultiProperty(String name) { super(name); } diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java index 659c7d9fc8b..2eeb12c0f24 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java @@ -20,11 +20,11 @@ public abstract class NumberProperty extends AbstractProperty { private static final long serialVersionUID = 240L; - public NumberProperty() { + protected NumberProperty() { super(); } - public NumberProperty(String name) { + protected NumberProperty(String name) { super(name); } diff --git a/src/core/src/main/java/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java b/src/core/src/main/java/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java index 9187a696341..b72dde6f276 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/gui/AbstractThreadGroupGui.java @@ -52,7 +52,7 @@ public abstract class AbstractThreadGroupGui extends AbstractJMeterGuiComponent private JRadioButton stopTestBox; private JRadioButton stopTestNowBox; - public AbstractThreadGroupGui(){ + protected AbstractThreadGroupGui(){ super(); init(); initGui(); diff --git a/src/core/src/main/java/org/apache/jmeter/util/BSFTestElement.java b/src/core/src/main/java/org/apache/jmeter/util/BSFTestElement.java index bc48ac7be9e..8b3a49f3ea3 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/BSFTestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/BSFTestElement.java @@ -51,7 +51,7 @@ public abstract class BSFTestElement extends ScriptingTestElement new String[]{"js"}); //$NON-NLS-1$ } - public BSFTestElement() { + protected BSFTestElement() { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java b/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java index 4667635fb23..a58a992f094 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java @@ -52,7 +52,7 @@ public abstract class BeanShellTestElement extends AbstractTestElement private transient boolean hasInitFile = false; - public BeanShellTestElement() { + protected BeanShellTestElement() { super(); init(); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java index e0f693c34c5..be2629b5c49 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java @@ -85,7 +85,7 @@ public static ScriptEngineManager getInstance() { return LazyHolder.INSTANCE; } - public JSR223TestElement() { + protected JSR223TestElement() { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/ScriptingBeanInfoSupport.java b/src/core/src/main/java/org/apache/jmeter/util/ScriptingBeanInfoSupport.java index 69f078757b3..e14b4e1249f 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/ScriptingBeanInfoSupport.java +++ b/src/core/src/main/java/org/apache/jmeter/util/ScriptingBeanInfoSupport.java @@ -40,7 +40,7 @@ public abstract class ScriptingBeanInfoSupport extends BeanInfoSupport { static final String FALSE_AS_STRING = Boolean.FALSE.toString(); static final String TRUE_AS_STRING = Boolean.TRUE.toString(); - public ScriptingBeanInfoSupport(Class beanClass, String[] languageTags) { + protected ScriptingBeanInfoSupport(Class beanClass, String[] languageTags) { this(beanClass, languageTags, null); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/ScriptingTestElement.java b/src/core/src/main/java/org/apache/jmeter/util/ScriptingTestElement.java index 6f2889f3564..b1a9a011f41 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/ScriptingTestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/ScriptingTestElement.java @@ -43,7 +43,7 @@ public abstract class ScriptingTestElement extends AbstractTestElement { //-- For TestBean implementations only - public ScriptingTestElement() { + protected ScriptingTestElement() { super(); } diff --git a/src/core/src/main/java/org/apache/jmeter/visualizers/gui/AbstractVisualizer.java b/src/core/src/main/java/org/apache/jmeter/visualizers/gui/AbstractVisualizer.java index 368af7968e6..68802c6723d 100644 --- a/src/core/src/main/java/org/apache/jmeter/visualizers/gui/AbstractVisualizer.java +++ b/src/core/src/main/java/org/apache/jmeter/visualizers/gui/AbstractVisualizer.java @@ -120,7 +120,7 @@ public abstract class AbstractVisualizer protected boolean isStats = false; - public AbstractVisualizer() { + protected AbstractVisualizer() { super(); // errorLogging and successOnlyLogging are mutually exclusive diff --git a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java index 7eaa5af095a..27c5074ddf0 100644 --- a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java +++ b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCaseJUnit.java @@ -38,11 +38,11 @@ public abstract class JMeterTestCaseJUnit extends TestCase { // Used by findTestFile private static final String filePrefix; - public JMeterTestCaseJUnit() { + protected JMeterTestCaseJUnit() { super(); } - public JMeterTestCaseJUnit(String name) { + protected JMeterTestCaseJUnit(String name) { super(name); } diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractFunctionByKey.java b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractFunctionByKey.java index 112f91583c9..878f90ac335 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractFunctionByKey.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractFunctionByKey.java @@ -35,7 +35,7 @@ abstract class AbstractFunctionByKey extends AbstractFunction { private Object[] values; - public AbstractFunctionByKey(String key, int parametersCount) { + protected AbstractFunctionByKey(String key, int parametersCount) { this.key = key; this.parametersCount = parametersCount; } diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java index 72836270b02..90a97d08ab1 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/AbstractHostIPName.java @@ -37,7 +37,7 @@ abstract class AbstractHostIPName extends AbstractFunction { private Object[] values; - public AbstractHostIPName() { + protected AbstractHostIPName() { } /** {@inheritDoc} */ diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/AbstractTreeTableModel.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/AbstractTreeTableModel.java index e1842471825..59e1022ab39 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/AbstractTreeTableModel.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/AbstractTreeTableModel.java @@ -45,13 +45,13 @@ public abstract class AbstractTreeTableModel extends DefaultTableModel implement protected final transient List writeFunctors; - public AbstractTreeTableModel(TreeNode root) { + protected AbstractTreeTableModel(TreeNode root) { this.rootNode = root; readFunctors = new ArrayList<>(); writeFunctors = new ArrayList<>(); } - public AbstractTreeTableModel(String[] headers, + protected AbstractTreeTableModel(String[] headers, Functor[] readFunctors, Functor[] writeFunctors, Class[] editorClasses) { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/BaseParser.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/BaseParser.java index 4726b51328c..296aa7988fe 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/BaseParser.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/BaseParser.java @@ -36,7 +36,7 @@ public abstract class BaseParser implements LinkExtractorParser { /** * Constructor for BaseParser */ - public BaseParser() { + protected BaseParser() { } /** diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java index 4dc12dc2866..ac27bb29b71 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/AbstractSamplerCreator.java @@ -73,7 +73,7 @@ public abstract class AbstractSamplerCreator implements SamplerCreator { } - public AbstractSamplerCreator() { + protected AbstractSamplerCreator() { super(); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 34dfd00469c..66b68e911dd 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -344,7 +344,7 @@ public abstract class HTTPSamplerBase extends AbstractSampler ////////////////////// Code /////////////////////////// - public HTTPSamplerBase() { + protected HTTPSamplerBase() { setArguments(new Arguments()); } diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java index bc9cede7ace..aa95fbf7635 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java @@ -28,7 +28,7 @@ public abstract class JDBCTestElementBeanInfoSupport extends BeanInfoSupport { /** * @param beanClass class to create bean info for */ - public JDBCTestElementBeanInfoSupport(Class beanClass) { + protected JDBCTestElementBeanInfoSupport(Class beanClass) { super(beanClass); createPropertyGroup("varName", // $NON-NLS-1$ diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java index 0612332cd6f..f9d91f28bd5 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java @@ -87,7 +87,7 @@ public abstract class BaseJMSSampler extends AbstractSampler { // See BUG 45460. We need to keep the resource in order to interpret existing files private static final String REQUIRED = JMeterUtils.getResString("jms_auth_required"); // $NON-NLS-1$ - public BaseJMSSampler() { + protected BaseJMSSampler() { } /** diff --git a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecorator.java b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecorator.java index 7f85c334e64..c9a15aa94d5 100644 --- a/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecorator.java +++ b/src/protocol/tcp/src/main/java/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecorator.java @@ -25,7 +25,7 @@ public abstract class TCPClientDecorator extends AbstractTCPClient { protected final TCPClient tcpClient; // the data implementation - public TCPClientDecorator(TCPClient tcpClient) { + protected TCPClientDecorator(TCPClient tcpClient) { this.tcpClient = tcpClient; } From 7e4213100dbfbe0689a951e36fa725f8b706ef71 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 17:02:57 +0300 Subject: [PATCH 14/40] Avoid import Map.Entry to avoid amboguity Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to See https://errorprone.info/bugpattern/BadImport --- .../org/apache/jmeter/visualizers/SamplerResultTab.java | 6 +++--- .../jmeter/engine/util/ReplaceFunctionsWithStrings.java | 3 +-- .../apache/jmeter/gui/action/SelectTemplatesDialog.java | 5 ++--- .../org/apache/jmeter/report/processor/MapResultData.java | 3 +-- .../main/java/org/apache/jmeter/reporters/Summariser.java | 3 +-- .../java/org/apache/jmeter/threads/JMeterVariables.java | 5 ++--- .../main/java/org/apache/jmeter/threads/ThreadGroup.java | 4 ++-- .../jmeter/threads/UnmodifiableJMeterVariables.java | 5 ++--- .../org/apache/jmeter/util/JSR223BeanInfoSupport.java | 3 +-- .../processor/graph/impl/CustomGraphConsumerTest.java | 3 +-- .../jmeter/threads/TestUnmodifiableJMeterVariables.java | 7 +++---- .../main/java/org/apache/jorphan/math/StatCalculator.java | 5 ++--- .../org/apache/jorphan/gui/ObjectTableSorterTest.java | 8 ++++---- .../jmeter/protocol/http/visualizers/RequestViewHTTP.java | 7 +++---- .../org/apache/jmeter/protocol/jms/client/Publisher.java | 3 +-- 15 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java index 50bca836a3f..0a4f6d6fe12 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java @@ -25,7 +25,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.LinkedHashMap; -import java.util.Map.Entry; +import java.util.Map; import java.util.Set; import javax.swing.BorderFactory; @@ -396,8 +396,8 @@ public void setupTabPane() { // Parsed response headers LinkedHashMap lhm = JMeterUtils.parseHeaders(sampleResult.getResponseHeaders()); - Set> keySet = lhm.entrySet(); - for (Entry entry : keySet) { + Set> keySet = lhm.entrySet(); + for (Map.Entry entry : keySet) { resHeadersModel.addRow(new RowResult(entry.getKey(), entry.getValue())); } diff --git a/src/core/src/main/java/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java b/src/core/src/main/java/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java index 26d230baffe..8ac37b9f58a 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/util/ReplaceFunctionsWithStrings.java @@ -18,7 +18,6 @@ package org.apache.jmeter.engine.util; import java.util.Map; -import java.util.Map.Entry; import org.apache.jmeter.functions.InvalidVariableException; import org.apache.jmeter.testelement.property.JMeterProperty; @@ -73,7 +72,7 @@ public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariable if(input == null) { return prop; } - for(Entry entry : getVariables().entrySet()){ + for(Map.Entry entry : getVariables().entrySet()){ String key = entry.getKey(); String value = entry.getValue(); if (regexMatch) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/SelectTemplatesDialog.java b/src/core/src/main/java/org/apache/jmeter/gui/action/SelectTemplatesDialog.java index bc75a90b0c2..9f017d7c9e0 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/SelectTemplatesDialog.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/SelectTemplatesDialog.java @@ -33,7 +33,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import javax.swing.AbstractAction; import javax.swing.Action; @@ -229,7 +228,7 @@ private boolean checkDirty(final ActionEvent actionEvent) { private Map getUserParameters(){ Map userParameters = new LinkedHashMap<>(); - for (Entry entry : parametersTextFields.entrySet()) { + for (Map.Entry entry : parametersTextFields.entrySet()) { userParameters.put(entry.getKey(), entry.getValue().getText()); } return userParameters; @@ -371,7 +370,7 @@ private JPanel configureParametersPanel(Map parameters) { int parameterCount = 0; JPanel gridbagpanel = new JPanel(new GridBagLayout()); - for (Entry entry : parameters.entrySet()) { + for (Map.Entry entry : parameters.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); JLabeledTextField paramLabel = new JLabeledTextField(key + " : "); diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/MapResultData.java b/src/core/src/main/java/org/apache/jmeter/report/processor/MapResultData.java index 65135805373..87c306e9e54 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/MapResultData.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/MapResultData.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; /** @@ -49,7 +48,7 @@ public T accept(ResultDataVisitor visitor) { * * @return the sets of entries of the map */ - public Set> entrySet() { + public Set> entrySet() { return map.entrySet(); } diff --git a/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java b/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java index 4b68eb97e04..ee56dbb6a2d 100644 --- a/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java +++ b/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java @@ -20,7 +20,6 @@ import java.io.Serializable; import java.text.DecimalFormat; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -295,7 +294,7 @@ public void testStarted(String host) { */ @Override public void testEnded(String host) { - Set> totals = null; + Set> totals = null; synchronized (LOCK) { instanceCount--; if (instanceCount <= 0){ diff --git a/src/core/src/main/java/org/apache/jmeter/threads/JMeterVariables.java b/src/core/src/main/java/org/apache/jmeter/threads/JMeterVariables.java index 85e2a521484..7f652380e77 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/JMeterVariables.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/JMeterVariables.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import org.apache.jmeter.util.JMeterUtils; @@ -161,7 +160,7 @@ public Object getObject(String key) { * * @return the iterator */ - public Iterator> getIterator(){ + public Iterator> getIterator(){ return Collections.unmodifiableMap(variables).entrySet().iterator() ; } @@ -169,7 +168,7 @@ public Iterator> getIterator(){ /** * @return an unmodifiable view of the entries contained in {@link JMeterVariables} */ - public Set> entrySet(){ + public Set> entrySet(){ return Collections.unmodifiableMap(variables).entrySet(); } diff --git a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java index d7d273218bc..5414b3594b5 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.io.ObjectInputStream; -import java.util.Map.Entry; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -349,7 +349,7 @@ public JMeterThread addNewThread(int delay, StandardJMeterEngine engine) { */ @Override public boolean stopThread(String threadName, boolean now) { - for (Entry threadEntry : allThreads.entrySet()) { + for (Map.Entry threadEntry : allThreads.entrySet()) { JMeterThread jMeterThread = threadEntry.getKey(); if (jMeterThread.getThreadName().equals(threadName)) { stopThread(jMeterThread, threadEntry.getValue(), now); diff --git a/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java b/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java index 515b526c5e5..cdd24deb3d8 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java @@ -19,7 +19,6 @@ import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; /** @@ -120,12 +119,12 @@ public Object getObject(String key) { } @Override - public Iterator> getIterator() { + public Iterator> getIterator() { return variables.getIterator(); } @Override - public Set> entrySet() { + public Set> entrySet() { return variables.entrySet(); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/JSR223BeanInfoSupport.java b/src/core/src/main/java/org/apache/jmeter/util/JSR223BeanInfoSupport.java index c9174c50317..825b45b2356 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JSR223BeanInfoSupport.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JSR223BeanInfoSupport.java @@ -23,7 +23,6 @@ import java.util.ListResourceBundle; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.ResourceBundle; import javax.script.ScriptEngineFactory; @@ -61,7 +60,7 @@ public abstract class JSR223BeanInfoSupport extends ScriptingBeanInfoSupport { Arrays.sort(LANGUAGE_TAGS); CONSTANT_LANGUAGE_NAMES = new String[nameMap.size()][2]; int i = 0; - for(Entry me : nameMap.entrySet()) { + for(Map.Entry me : nameMap.entrySet()) { final String key = me.getKey(); CONSTANT_LANGUAGE_NAMES[i][0] = key; final ScriptEngineFactory fact = me.getValue(); diff --git a/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java b/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java index 123d33c24be..30569724327 100644 --- a/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java +++ b/src/core/src/test/java/org/apache/jmeter/report/processor/graph/impl/CustomGraphConsumerTest.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import org.apache.jmeter.report.core.Sample; import org.apache.jmeter.report.core.SampleMetadata; @@ -83,7 +82,7 @@ public void testInitializeExtraResults() { customGraphConsumer.initializeExtraResults(resultData); JsonizerVisitor jsonizer = new JsonizerVisitor(); - for (Entry entrySet : resultData.entrySet()) { + for (Map.Entry entrySet : resultData.entrySet()) { Object testedValue = entrySet.getValue().accept(jsonizer); String key = entrySet.getKey(); diff --git a/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java b/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java index 0cc6306101c..fef4df0dec1 100644 --- a/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java +++ b/src/core/src/test/java/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Assertions; @@ -103,7 +102,7 @@ public void testGetObject() { @Test public void testGetIteratorIsUnmodifable() { - Iterator> iterator = unmodifiables.getIterator(); + Iterator> iterator = unmodifiables.getIterator(); assertThat(iterator.hasNext(), CoreMatchers.is(true)); iterator.next(); assertThrowsUnsupportedOperation(iterator::remove); @@ -121,10 +120,10 @@ public void testGetIterator() { assertThat(iteratorToMap(unmodifiables.getIterator()), CoreMatchers.is(iteratorToMap(vars.getIterator()))); } - private Map iteratorToMap(Iterator> it) { + private Map iteratorToMap(Iterator> it) { Map result = new HashMap<>(); while (it.hasNext()) { - Entry entry = it.next(); + Map.Entry entry = it.next(); result.put(entry.getKey(), entry.getValue()); } return result; diff --git a/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java b/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java index 4c908afbda1..736d42d7420 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java @@ -20,7 +20,6 @@ import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.TreeMap; import org.apache.commons.lang3.mutable.MutableLong; @@ -109,7 +108,7 @@ public void addSentBytes(long newValue) { } public void addAll(StatCalculator calc) { - for(Entry ent : calc.valuesMap.entrySet()) { + for(Map.Entry ent : calc.valuesMap.entrySet()) { addEachValue(ent.getKey(), ent.getValue().longValue()); } } @@ -184,7 +183,7 @@ public T getPercentPoint(double percent) { public Map getDistribution() { Map items = new HashMap<>(); - for (Entry entry : valuesMap.entrySet()) { + for (Map.Entry entry : valuesMap.entrySet()) { Number[] dis = new Number[2]; dis[0] = entry.getKey(); dis[1] = entry.getValue(); diff --git a/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java b/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java index 79a1e9a62d7..855a0933b3d 100644 --- a/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java +++ b/src/jorphan/src/test/java/org/apache/jorphan/gui/ObjectTableSorterTest.java @@ -39,7 +39,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; -import java.util.Map.Entry; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -64,7 +64,7 @@ public void createModelAndSorter() { Class[] editorClasses = {String.class, Integer.class, Object.class}; ObjectTableModel model = new ObjectTableModel(headers, readFunctors, writeFunctors, editorClasses); sorter = new ObjectTableSorter(model); - List> data = asList(b2(), a3(), d4(), c1()); + List> data = asList(b2(), a3(), d4(), c1()); data.forEach(model::addRow); } @@ -247,11 +247,11 @@ public void setSortKeys_invalidColumn() { } @SuppressWarnings("unchecked") - protected List> actual() { + protected List> actual() { return IntStream .range(0, sorter.getViewRowCount()) .map(sorter::convertRowIndexToModel) - .mapToObj(modelIndex -> (Entry) sorter.getModel().getObjectListAsList().get(modelIndex)) + .mapToObj(modelIndex -> (Map.Entry) sorter.getModel().getObjectListAsList().get(modelIndex)) .collect(Collectors.toList()) ; } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java index 5b7c70747d8..feb6494cbe6 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java @@ -26,7 +26,6 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -181,7 +180,7 @@ public void setSamplerResult(Object objectResult) { // Parsed request headers LinkedHashMap lhm = JMeterUtils.parseHeaders(sampleResult.getRequestHeaders()); - for (Entry entry : lhm.entrySet()) { + for (Map.Entry entry : lhm.entrySet()) { headersModel.addRow(new RowResult(entry.getKey(), entry.getValue())); } @@ -214,8 +213,8 @@ public void setSamplerResult(Object objectResult) { } if (StringUtils.isNotBlank(queryGet)) { - Set> keys = RequestViewHTTP.getQueryMap(queryGet).entrySet(); - for (Entry entry : keys) { + Set> keys = RequestViewHTTP.getQueryMap(queryGet).entrySet(); + for (Map.Entry entry : keys) { for (String value : entry.getValue()) { paramsModel.addRow(new RowResult(entry.getKey(), value)); } diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java index a578a122845..ddf08a88962 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/client/Publisher.java @@ -20,7 +20,6 @@ import java.io.Closeable; import java.io.Serializable; import java.util.Map; -import java.util.Map.Entry; import javax.jms.BytesMessage; import javax.jms.Connection; @@ -166,7 +165,7 @@ public MapMessage publish(Map map, String destinationName, Map me : map.entrySet()) { + for (Map.Entry me : map.entrySet()) { msg.setObject(me.getKey(), me.getValue()); } return (MapMessage)setPropertiesAndSend(destinationName, properties, msg, deliveryMode, priority, expiration); From 93e27d784c29dce224d0f3d77c2d7e04ba1ca767 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 17:36:46 +0300 Subject: [PATCH 15/40] Use lower-case field names for non-static fields in StatCalculator --- .../apache/jorphan/math/StatCalculator.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java b/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java index 736d42d7420..6136f15da8f 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/math/StatCalculator.java @@ -56,11 +56,11 @@ public abstract class StatCalculator> { private long sentBytes = 0; - private final T ZERO; + private final T zero; - private final T MAX_VALUE; // e.g. Long.MAX_VALUE + private final T maxValue; // e.g. Long.MAX_VALUE - private final T MIN_VALUE; // e.g. Long.MIN_VALUE + private final T minValue; // e.g. Long.MIN_VALUE /** * This constructor is used to set up particular values for the generic class instance. @@ -69,13 +69,12 @@ public abstract class StatCalculator> { * @param min - value to return for minimum if there are no values * @param max - value to return for maximum if there are no values */ - public StatCalculator(final T zero, final T min, final T max) { - super(); - ZERO = zero; - MAX_VALUE = max; - MIN_VALUE = min; - this.min = MAX_VALUE; - this.max = MIN_VALUE; + protected StatCalculator(final T zero, final T min, final T max) { + this.zero = zero; + this.maxValue = max; + this.minValue = min; + this.min = maxValue; + this.max = minValue; } public void clear() { @@ -87,8 +86,8 @@ public void clear() { count = 0; bytes = 0; sentBytes = 0; - max = MIN_VALUE; - min = MAX_VALUE; + max = minValue; + min = maxValue; } /** @@ -153,7 +152,7 @@ public T getPercentPoint(float percent) { */ public T getPercentPoint(double percent) { if (count <= 0) { - return ZERO; + return zero; } if (percent >= 1.0) { return getMax(); @@ -162,7 +161,7 @@ public T getPercentPoint(double percent) { // use Math.round () instead of simple (long) to provide correct value rounding long target = Math.round(count * percent); try { - for (Entry val : valuesMap.entrySet()) { + for (Map.Entry val : valuesMap.entrySet()) { target -= val.getValue().longValue(); if (target <= 0){ return val.getKey(); @@ -171,7 +170,7 @@ public T getPercentPoint(double percent) { } catch (ConcurrentModificationException ignored) { // ignored. May happen occasionally, but no harm done if so. } - return ZERO; // TODO should this be getMin()? + return zero; // TODO should this be getMin()? } /** From dc4bdc06f0db89550a5de8a97750f9f2aed6d162 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 17:40:15 +0300 Subject: [PATCH 16/40] Make enums immutable --- .../org/apache/jmeter/functions/ChangeCase.java | 2 +- .../java/org/apache/jorphan/gui/MenuScroller.java | 2 ++ .../jms/sampler/render/RendererFactory.java | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java b/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java index 2a16a12d885..56a98b9fd1b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/ChangeCase.java @@ -123,7 +123,7 @@ public List getArgumentDesc() { */ public enum ChangeCaseMode { UPPER("UPPER"), LOWER("LOWER"), CAPITALIZE("CAPITALIZE"); - private String mode; + private final String mode; private ChangeCaseMode(String mode) { this.mode = mode; diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java index d1838dd884a..60455c9ef1a 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/MenuScroller.java @@ -669,7 +669,9 @@ public void stateChanged(ChangeEvent e) { private enum MenuIcon implements Icon { UP(9, 1, 9), DOWN(1, 9, 1); + @SuppressWarnings("ImmutableEnumChecker") final int[] xPoints = { 1, 5, 9 }; + @SuppressWarnings("ImmutableEnumChecker") final int[] yPoints; MenuIcon(int... yPoints) { diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/render/RendererFactory.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/render/RendererFactory.java index 4779ac59982..522fb660034 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/render/RendererFactory.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/render/RendererFactory.java @@ -33,13 +33,18 @@ public static RendererFactory getInstance() { return INSTANCE; } - private TextMessageRenderer text = new TextMessageRenderer(); - private BinaryMessageRenderer binary = new BinaryMessageRenderer(text); - private ObjectMessageRenderer object = new ObjectMessageRenderer(text); - private MapMessageRenderer map = new MapMessageRenderer(text); + @SuppressWarnings("ImmutableEnumChecker") + private final TextMessageRenderer text = new TextMessageRenderer(); + @SuppressWarnings("ImmutableEnumChecker") + private final BinaryMessageRenderer binary = new BinaryMessageRenderer(text); + @SuppressWarnings("ImmutableEnumChecker") + private final ObjectMessageRenderer object = new ObjectMessageRenderer(text); + @SuppressWarnings("ImmutableEnumChecker") + private final MapMessageRenderer map = new MapMessageRenderer(text); /** Registered renderers **/ - private Map, MessageRenderer> renderers; + @SuppressWarnings("ImmutableEnumChecker") + private final Map, MessageRenderer> renderers; { Map, MessageRenderer> writable = new LinkedHashMap<>(); writable.put(String.class, text); From 63d791cf7cd977f291c21ce5f698d1f64142ecfb Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 17:41:28 +0300 Subject: [PATCH 17/40] Suppresss MissingSummary and EmptyBlockTag for now The code contains too many JavaDoc warnings --- build.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 45e554e6b19..453627316a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -393,6 +393,7 @@ allprojects { "annotationProcessor"("com.google.guava:guava-beta-checker:1.0") } tasks.withType().configureEach { + options.compilerArgs.addAll(listOf("-Xmaxerrs", "10000", "-Xmaxwarns", "10000")) options.errorprone { disableWarningsInGeneratedCode.set(true) errorproneArgs.add("-XepExcludedPaths:.*/javacc/.*") @@ -407,6 +408,8 @@ allprojects { ) // Analyze issues, and enable the check disable( + "MissingSummary", + "EmptyBlockTag", "BigDecimalEquals", "StringSplitter" ) From 599fcc97e92792c5053be41fcc17a488b2744e67 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 18:21:37 +0300 Subject: [PATCH 18/40] Suppress deprecation warnings for TestResultAction --- .../java/org/apache/jmeter/listeners/TestResultAction.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/src/test/java/org/apache/jmeter/listeners/TestResultAction.java b/src/core/src/test/java/org/apache/jmeter/listeners/TestResultAction.java index 7b286c253ba..72b6cbc35b4 100644 --- a/src/core/src/test/java/org/apache/jmeter/listeners/TestResultAction.java +++ b/src/core/src/test/java/org/apache/jmeter/listeners/TestResultAction.java @@ -53,6 +53,7 @@ public void testSuccess() { } @Test + @SuppressWarnings("deprecation") public void testOnFailureStopTest() { sampleResult.setSuccessful(false); resultAction.setErrorAction(ResultAction.ON_ERROR_STOPTEST); @@ -64,6 +65,7 @@ public void testOnFailureStopTest() { } @Test + @SuppressWarnings("deprecation") public void testOnFailureStopTestNow() { sampleResult.setSuccessful(false); resultAction.setErrorAction(ResultAction.ON_ERROR_STOPTEST_NOW); @@ -75,6 +77,7 @@ public void testOnFailureStopTestNow() { } @Test + @SuppressWarnings("deprecation") public void testOnFailureStopThread() { sampleResult.setSuccessful(false); resultAction.setErrorAction(ResultAction.ON_ERROR_STOPTHREAD); @@ -86,6 +89,7 @@ public void testOnFailureStopThread() { } @Test + @SuppressWarnings("deprecation") public void testOnFailureStartNextThreadLoop() { sampleResult.setSuccessful(false); resultAction.setErrorAction(ResultAction.ON_ERROR_START_NEXT_THREAD_LOOP); From 2fde32bfb1627e9f01dc78bcaed973c01d2abd0a Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 18:32:00 +0300 Subject: [PATCH 19/40] Suppress deprecation warnings in SamplerMetricFixedModeTest --- .../jmeter/visualizers/backend/SamplerMetricFixedModeTest.java | 2 +- .../jmeter/visualizers/backend/SamplerMetricTimedModeTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java index fe15a5405bf..4286f5840d3 100644 --- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java +++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java @@ -32,8 +32,8 @@ public class SamplerMetricFixedModeTest { private static final double ALLOWED_DELTA = 25.0; @BeforeEach + @SuppressWarnings("deprecation") public void initMode() throws Exception { - //noinspection deprecation SamplerMetric.setDefaultWindowMode(WindowMode.FIXED); } diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java index 4de3a0fedb5..ba9fa7f77fe 100644 --- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java +++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java @@ -32,8 +32,8 @@ public class SamplerMetricTimedModeTest { private static final double ALLOWED_DELTA = 25.0; @BeforeEach + @SuppressWarnings("deprecation") public void initMode() throws Exception { - // noinspection deprecation SamplerMetric.setDefaultWindowMode(WindowMode.TIMED); } From 80c39149ef977f87ee03cddb0b99a21629126ce5 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 19:35:07 +0300 Subject: [PATCH 20/40] Suppress DefaultCharset usage: either suppress the warning or use a charset --- .../jmeter/assertions/HTMLAssertion.java | 6 ++++-- .../backend/influxdb/UdpMetricsSender.java | 3 ++- .../main/java/org/apache/jmeter/JMeter.java | 5 +++-- .../jmeter/report/dashboard/JsonExporter.java | 9 +++++---- .../jmeter/reporters/ResultCollector.java | 11 +++++------ .../apache/jmeter/services/FileServer.java | 16 ++++++++++------ .../org/apache/jmeter/util/JMeterUtils.java | 7 ++++--- .../apache/jmeter/util/JSR223TestElement.java | 13 ++++--------- .../jmeter/functions/StringFromFile.java | 17 +++-------------- .../protocol/bolt/sampler/BoltSampler.java | 4 +++- .../protocol/ftp/sampler/FTPSampler.java | 1 + .../protocol/http/control/AuthManager.java | 6 +++--- .../protocol/http/control/CookieManager.java | 16 +++++----------- .../protocol/http/control/HeaderManager.java | 6 +++--- .../jmeter/protocol/http/proxy/Proxy.java | 8 ++++++-- .../protocol/http/proxy/ProxyControl.java | 2 +- .../protocol/http/sampler/AjpSampler.java | 1 + .../protocol/http/sampler/HTTPHC4Impl.java | 3 ++- .../protocol/http/sampler/PostWriter.java | 19 ++++--------------- .../protocol/http/util/Base64Encoder.java | 1 + .../http/util/accesslog/TCLogParser.java | 3 ++- .../jdbc/AbstractJDBCTestElement.java | 2 +- .../protocol/jdbc/sampler/JDBCSampler.java | 6 ++++-- .../protocol/jms/sampler/JMSSampler.java | 4 ++-- .../jms/sampler/SubscriberSampler.java | 2 +- .../mongodb/sampler/MongoScriptSampler.java | 4 ++-- .../jmeter/protocol/system/SystemSampler.java | 4 +++- 27 files changed, 85 insertions(+), 94 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/HTMLAssertion.java b/src/components/src/main/java/org/apache/jmeter/assertions/HTMLAssertion.java index d9c1a143d11..8fc41ea1cdd 100644 --- a/src/components/src/main/java/org/apache/jmeter/assertions/HTMLAssertion.java +++ b/src/components/src/main/java/org/apache/jmeter/assertions/HTMLAssertion.java @@ -19,12 +19,14 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; +import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.text.MessageFormat; import org.apache.commons.lang3.StringUtils; @@ -191,7 +193,7 @@ private void writeOutput(String inOutput) { // check if filename defined if (StringUtils.isNotBlank(filename)) { - try (FileWriter writer = new FileWriter(filename, false)){ + try (Writer writer = Files.newBufferedWriter(Paths.get(filename))) { // write to file writer.write(inOutput); log.debug("writeOutput() -> output successfully written to file: {}", filename); diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/UdpMetricsSender.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/UdpMetricsSender.java index 48d31c3b175..be73a237b26 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/UdpMetricsSender.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/UdpMetricsSender.java @@ -22,6 +22,7 @@ import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -99,7 +100,7 @@ public void writeAndSendMetrics() { } try (DatagramSocket ds = new DatagramSocket()) { - byte[] buf = sb.toString().getBytes(); + byte[] buf = sb.toString().getBytes(StandardCharsets.UTF_8); DatagramPacket dp = new DatagramPacket(buf, buf.length, this.hostAddress, this.udpPort); ds.send(dp); } catch (SocketException e) { diff --git a/src/core/src/main/java/org/apache/jmeter/JMeter.java b/src/core/src/main/java/org/apache/jmeter/JMeter.java index 3feca429d2d..0d1626d0101 100644 --- a/src/core/src/main/java/org/apache/jmeter/JMeter.java +++ b/src/core/src/main/java/org/apache/jmeter/JMeter.java @@ -21,9 +21,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.Reader; import java.net.Authenticator; import java.net.DatagramPacket; import java.net.DatagramSocket; @@ -31,6 +31,7 @@ import java.net.MalformedURLException; import java.net.SocketException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; @@ -711,7 +712,7 @@ void runInitScripts() { File file = new File(jsr223Init); if(file.exists() && file.canRead()) { String extension = StringUtils.defaultIfBlank(FilenameUtils.getExtension(jsr223Init), "Groovy"); - try (FileReader reader = new FileReader(file)) { + try (Reader reader = Files.newBufferedReader(file.toPath())) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByExtension(extension); if (engine == null) { diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonExporter.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonExporter.java index 8fffcec9713..f8bb25b7425 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonExporter.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/JsonExporter.java @@ -19,8 +19,9 @@ import java.io.File; import java.io.FileFilter; -import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -51,6 +52,7 @@ public class JsonExporter extends AbstractDataExporter { public static final String OUTPUT_FILENAME = "statistics.json"; private static final FileFilter JSON_FILE_FILTER = file -> file.isFile() && file.getName().equals(OUTPUT_FILENAME); + private final static ObjectWriter OBJECT_WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter(); public JsonExporter() { @@ -78,9 +80,8 @@ public void export(SampleContext context, File file, ReportGeneratorConfiguratio File outputFile = new File(outputDir, OUTPUT_FILENAME); LOGGER.info("Writing statistics JSON to {}", outputFile); - ObjectWriter objectWriter = new ObjectMapper().writerWithDefaultPrettyPrinter(); - try (FileWriter fileWriter = new FileWriter(outputFile)) { - objectWriter.writeValue(fileWriter, statistics); + try (Writer fileWriter = Files.newBufferedWriter(outputFile.toPath())) { + OBJECT_WRITER.writeValue(fileWriter, statistics); } catch (IOException e) { throw new ExportException("Error generating JSON statistics file to " + outputFile +" for "+statistics, e); } diff --git a/src/core/src/main/java/org/apache/jmeter/reporters/ResultCollector.java b/src/core/src/main/java/org/apache/jmeter/reporters/ResultCollector.java index 7326c87f8ae..0138e1c2528 100644 --- a/src/core/src/main/java/org/apache/jmeter/reporters/ResultCollector.java +++ b/src/core/src/main/java/org/apache/jmeter/reporters/ResultCollector.java @@ -21,16 +21,16 @@ import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.RandomAccessFile; import java.io.Serializable; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; @@ -368,8 +368,7 @@ public void loadExistingFile() { String filename = getFilename(); File file = new File(filename); if (file.exists()) { - try ( FileReader fr = new FileReader(file); - BufferedReader dataReader = new BufferedReader(fr, 300)){ + try (BufferedReader dataReader = Files.newBufferedReader(file.toPath())){ // Get the first line, and see if it is XML String line = dataReader.readLine(); dataReader.close(); @@ -380,8 +379,8 @@ public void loadExistingFile() { CSVSaveService.processSamples(filename, visualizer, this); parsedOK = true; } else { // We are processing XML - try ( FileInputStream fis = new FileInputStream(file); - BufferedInputStream bufferedInputStream = new BufferedInputStream(fis); ){ // Assume XStream + try (InputStream fis = Files.newInputStream(file.toPath()); + BufferedInputStream bufferedInputStream = new BufferedInputStream(fis); ){ // Assume XStream SaveService.loadTestResults(bufferedInputStream, new ResultCollectorHelper(this, visualizer)); parsedOK = true; diff --git a/src/core/src/main/java/org/apache/jmeter/services/FileServer.java b/src/core/src/main/java/org/apache/jmeter/services/FileServer.java index 534cdac7f26..dfa6e00690b 100644 --- a/src/core/src/main/java/org/apache/jmeter/services/FileServer.java +++ b/src/core/src/main/java/org/apache/jmeter/services/FileServer.java @@ -22,13 +22,13 @@ import java.io.Closeable; import java.io.EOFException; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.nio.file.Files; import java.util.ArrayDeque; import java.util.HashMap; import java.util.Map; @@ -423,7 +423,7 @@ private BufferedReader createBufferedReader(FileEntry fileEntry) throws IOExcept if (!fileEntry.file.canRead() || !fileEntry.file.isFile()) { throw new IllegalArgumentException("File "+ fileEntry.file.getName()+ " must exist and be readable"); } - BOMInputStream fis = new BOMInputStream(new FileInputStream(fileEntry.file)); //NOSONAR + BOMInputStream fis = new BOMInputStream(Files.newInputStream(fileEntry.file.toPath())); //NOSONAR InputStreamReader isr = null; // If file encoding is specified, read using that encoding, otherwise use default platform encoding String charsetName = fileEntry.charSetEncoding; @@ -432,7 +432,9 @@ private BufferedReader createBufferedReader(FileEntry fileEntry) throws IOExcept } else if (fis.hasBOM()) { isr = new InputStreamReader(fis, fis.getBOM().getCharsetName()); } else { - isr = new InputStreamReader(fis); + @SuppressWarnings("DefaultCharset") + final InputStreamReader withPlatformEncoding = new InputStreamReader(fis); + isr = withPlatformEncoding; } return new BufferedReader(isr); } @@ -454,14 +456,16 @@ public synchronized void write(String filename, String value) throws IOException } private BufferedWriter createBufferedWriter(FileEntry fileEntry) throws IOException { - FileOutputStream fos = new FileOutputStream(fileEntry.file); + OutputStream fos = Files.newOutputStream(fileEntry.file.toPath()); OutputStreamWriter osw; // If file encoding is specified, write using that encoding, otherwise use default platform encoding String charsetName = fileEntry.charSetEncoding; if(!JOrphanUtils.isBlank(charsetName)) { osw = new OutputStreamWriter(fos, charsetName); } else { - osw = new OutputStreamWriter(fos); + @SuppressWarnings("DefaultCharset") + final OutputStreamWriter withPlatformEncoding = new OutputStreamWriter(fos); + osw = withPlatformEncoding; } return new BufferedWriter(osw); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java b/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java index c2123a18141..8974bf509bb 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java @@ -30,6 +30,7 @@ import java.net.InetAddress; import java.net.URL; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; @@ -655,9 +656,9 @@ public static String getResourceFileAsText(String name) { try { String lineEnd = System.getProperty("line.separator"); // $NON-NLS-1$ InputStream is = JMeterUtils.class.getClassLoader().getResourceAsStream(name); - if(is != null) { - try (Reader in = new InputStreamReader(is); - BufferedReader fileReader = new BufferedReader(in)) { + if (is != null) { + try (Reader in = new InputStreamReader(is, StandardCharsets.UTF_8); + BufferedReader fileReader = new BufferedReader(in)) { return fileReader.lines() .collect(Collectors.joining(lineEnd, "", lineEnd)); } diff --git a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java index be2629b5c49..7ad70819f45 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java +++ b/src/core/src/main/java/org/apache/jmeter/util/JSR223TestElement.java @@ -19,9 +19,9 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.Serializable; +import java.nio.file.Files; import java.util.Collections; import java.util.Map; import java.util.Properties; @@ -182,9 +182,7 @@ protected Object processFileOrScript(ScriptEngine scriptEngine, final Bindings p synchronized (compiledScriptsCache) { compiledScript = compiledScriptsCache.get(newCacheKey); if (compiledScript == null) { - // TODO Charset ? - try (BufferedReader fileReader = new BufferedReader(new FileReader(scriptFile), - (int) scriptFile.length())) { + try (BufferedReader fileReader = Files.newBufferedReader(scriptFile.toPath())) { compiledScript = ((Compilable) scriptEngine).compile(fileReader); compiledScriptsCache.put(newCacheKey, compiledScript); } @@ -193,9 +191,7 @@ protected Object processFileOrScript(ScriptEngine scriptEngine, final Bindings p } return compiledScript.eval(bindings); } else { - // TODO Charset ? - try (BufferedReader fileReader = new BufferedReader(new FileReader(scriptFile), - (int) scriptFile.length())) { + try (BufferedReader fileReader = Files.newBufferedReader(scriptFile.toPath())) { return scriptEngine.eval(fileReader, bindings); } } @@ -259,8 +255,7 @@ public boolean compile() } } else { File scriptFile = new File(getFilename()); - try (BufferedReader fileReader = new BufferedReader(new FileReader(scriptFile), - (int) scriptFile.length())) { + try (BufferedReader fileReader = Files.newBufferedReader(scriptFile.toPath())) { try { ((Compilable) scriptEngine).compile(fileReader); return true; diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java index 2b154c42077..e1b221da7fa 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/StringFromFile.java @@ -18,8 +18,9 @@ package org.apache.jmeter.functions; import java.io.BufferedReader; -import java.io.FileReader; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; @@ -101,9 +102,6 @@ public class StringFromFile extends AbstractFunction implements TestStateListene // @GuardedBy("this") private Object[] values; - // @GuardedBy("this") - private FileReader myFileReader = null; // File reader - // @GuardedBy("this") private BufferedReader myBread = null; // Buffered reader @@ -143,12 +141,6 @@ private synchronized void closeFile() { } catch (IOException e) { log.error("closeFile() error: {}", e.toString(), e);//$NON-NLS-1$ } - - try { - myFileReader.close(); - } catch (IOException e) { - log.error("closeFile() error: {}", e.toString(), e);//$NON-NLS-1$ - } } private synchronized void openFile() { @@ -218,14 +210,11 @@ private synchronized void openFile() { log.info("{} opening file {}", tn, fileName);//$NON-NLS-1$ try { - myFileReader = new FileReader(fileName); - myBread = new BufferedReader(myFileReader); + myBread = Files.newBufferedReader(Paths.get(fileName)); } catch (Exception e) { log.error("openFile() error: {}", e.toString());//$NON-NLS-1$ - IOUtils.closeQuietly(myFileReader, null); IOUtils.closeQuietly(myBread, null); myBread = null; - myFileReader = null; } } diff --git a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java index 1eb2b9c079f..03b2c435379 100644 --- a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java +++ b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java @@ -114,7 +114,9 @@ private SampleResult handleException(SampleResult res, Exception ex) { } else { res.setResponseCode("500"); } - res.setResponseData(ObjectUtils.defaultIfNull(ex.getMessage(), "NO MESSAGE").getBytes()); + res.setResponseData( + ObjectUtils.defaultIfNull(ex.getMessage(), "NO MESSAGE"), + res.getDataEncodingNoDefault()); res.setSuccessful(false); return res; } diff --git a/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java b/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java index d2789a63fb8..b615d47217e 100644 --- a/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java +++ b/src/protocol/ftp/src/main/java/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java @@ -207,6 +207,7 @@ public SampleResult sample(Entry e) { if (isUpload()) { String contents=getLocalFileContents(); if (contents.length() > 0){ + @SuppressWarnings("DefaultCharset") byte[] bytes = contents.getBytes(); // TODO - charset? input = new ByteArrayInputStream(bytes); res.setSentBytes((long)bytes.length); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/AuthManager.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/AuthManager.java index 4d0d2aed3b9..d88e2c05479 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/AuthManager.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/AuthManager.java @@ -18,8 +18,8 @@ package org.apache.jmeter.protocol.http.control; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; @@ -357,8 +357,8 @@ public void save(String authFile) throws IOException { if (!file.isAbsolute()) { file = new File(System.getProperty("user.dir"),authFile); } - try (FileWriter fw = new FileWriter(file); - PrintWriter writer = new PrintWriter(fw)){ + try (BufferedWriter fw = Files.newBufferedWriter(file.toPath()); + PrintWriter writer = new PrintWriter(fw)){ writer.println("# JMeter generated Authorization file"); for (int i = 0; i < getAuthObjects().size(); i++) { Authorization auth = (Authorization) getAuthObjects().get(i).getObjectValue(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CookieManager.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CookieManager.java index 535a6927f83..97906210ca4 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CookieManager.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/CookieManager.java @@ -19,12 +19,11 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import org.apache.http.client.config.CookieSpecs; @@ -183,7 +182,7 @@ public void save(String authFile) throws IOException { file = new File(System.getProperty("user.dir") // $NON-NLS-1$ + File.separator + authFile); } - try(PrintWriter writer = new PrintWriter(new FileWriter(file))) { // TODO Charset ? + try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file.toPath()))) { writer.println("# JMeter generated Cookie file");// $NON-NLS-1$ long now = System.currentTimeMillis(); for (JMeterProperty jMeterProperty : getCookies()) { @@ -213,16 +212,13 @@ public void addFile(String cookieFile) throws IOException { file = new File(System.getProperty("user.dir") // $NON-NLS-1$ + File.separator + cookieFile); } - BufferedReader reader = null; - if (file.canRead()) { - reader = new BufferedReader(new FileReader(file)); // TODO Charset ? - } else { + if (!file.canRead()) { throw new IOException("The file you specified cannot be read."); } // N.B. this must agree with the save() and cookieToString() methods String line; - try { + try (BufferedReader reader = Files.newBufferedReader(file.toPath())) { final CollectionProperty cookies = getCookies(); while ((line = reader.readLine()) != null) { try { @@ -258,9 +254,7 @@ public void addFile(String cookieFile) throws IOException { throw new IOException("Error parsing cookie line\n\t'" + line + "'\n\t" + e); } } - } finally { - reader.close(); - } + } } private String cookieToString(Cookie c){ diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HeaderManager.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HeaderManager.java index 02d5b3975ec..5b63c98b491 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HeaderManager.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HeaderManager.java @@ -18,8 +18,8 @@ package org.apache.jmeter.protocol.http.control; import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; @@ -104,8 +104,8 @@ public void save(String headFile) throws IOException { file = new File(System.getProperty("user.dir")// $NON-NLS-1$ + File.separator + headFile); } - try ( FileWriter fw = new FileWriter(file); - PrintWriter writer = new PrintWriter(fw);) { // TODO Charset ? + try (BufferedWriter fw = Files.newBufferedWriter(file.toPath()); + PrintWriter writer = new PrintWriter(fw);) { // TODO Charset ? writer.println("# JMeter generated Header file");// $NON-NLS-1$ final CollectionProperty hdrs = getHeaders(); for (int i = 0; i < hdrs.size(); i++) { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java index 21a228834f2..ad732efdb9d 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/Proxy.java @@ -180,7 +180,9 @@ public void run() { throw new JMeterException(); // hack to skip processing } if (isDebug) { - log.debug("{} Initial request: {}", port, new String(ba)); // NOSONAR False positive + @SuppressWarnings("DefaultCharset") + final String reparsed = new String(ba); // NOSONAR False positive + log.debug("{} Initial request: {}", port, reparsed); } // Use with SSL connection OutputStream outStreamClient = clientSocket.getOutputStream(); @@ -214,7 +216,9 @@ public void run() { throw new JMeterException(); // hack to skip processing } if (isDebug) { - log.debug("{} Reparse: {}", port, new String(ba)); // NOSONAR False positive + @SuppressWarnings("DefaultCharset") + final String reparsed = new String(ba); // NOSONAR False positive + log.debug("{} Reparse: {}", port, reparsed); } if (ba.length == 0) { log.warn("{} Empty response to http over SSL. Probably waiting for user to authorize the certificate for {}", diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java index ffedff91e1c..9055db46010 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/ProxyControl.java @@ -718,7 +718,7 @@ private Authorization createAuthorization(final TestElement[] testElements, HTTP } authorization.setMechanism(mechanism); if(BASIC_AUTH.equals(authType)) { - String authCred= new String(Base64.decodeBase64(authCredentialsBase64)); + String authCred = new String(Base64.decodeBase64(authCredentialsBase64), StandardCharsets.UTF_8); String[] loginPassword = authCred.split(":"); //$NON-NLS-1$ if(loginPassword.length == 2) { authorization.setUser(loginPassword[0]); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java index 8233f9f8e99..8a049dbc7f8 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/AjpSampler.java @@ -288,6 +288,7 @@ private String setConnectionHeaders(URL url, String host, String method) sb.append(arg.getStringValue()); } stringBody = sb.toString(); + @SuppressWarnings("DefaultCharset") byte [] sbody = stringBody.getBytes(); // TODO - charset? cl = sbody.length; body = new ByteArrayInputStream(sbody); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index 9b8715e4af2..47c26fc0729 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -30,6 +30,7 @@ import java.net.URL; import java.net.URLDecoder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -1505,7 +1506,7 @@ public ViewableFileBody(File file, ContentType contentType) { @Override public void writeTo(final OutputStream out) throws IOException { if (hideFileData) { - out.write("".getBytes());// encoding does not really matter here + out.write("".getBytes(StandardCharsets.UTF_8)); } else { super.writeTo(out); } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java index 6d01e3d46b8..b67b1173e12 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/PostWriter.java @@ -33,7 +33,6 @@ import org.apache.jmeter.protocol.http.util.HTTPFileArg; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testelement.property.JMeterProperty; -import org.apache.jorphan.util.JOrphanUtils; /** * Class for setting the necessary headers for a POST request, and sending the @@ -114,10 +113,11 @@ public String sendPostData(URLConnection connection, HTTPSamplerBase sampler) th for (int i=0; i < files.length; i++) { HTTPFileArg file = files[i]; // First write the start multipart file - byte[] header = file.getHeader().getBytes(); // TODO - charset? + final String headerValue = file.getHeader(); + byte[] header = headerValue.getBytes(ENCODING); out.write(header); // Retrieve the formatted data using the same encoding used to create it - postedBody.append(new String(header)); // TODO - charset? + postedBody.append(headerValue); // Write the actual file content writeFileToStream(file.getPath(), out); // We just add placeholder text for file content @@ -411,22 +411,11 @@ private static void writeFileToStream(String filename, OutputStream out) throws // elsewhere in the chain) and it caused OOM when many concurrent // uploads were being done. Could be fixed by increasing the evacuation // ratio in bin/jmeter[.bat], but this is better. - InputStream in = new BufferedInputStream(new FileInputStream(filename)); int read; - boolean noException = false; - try { + try (InputStream in = new BufferedInputStream(new FileInputStream(filename))) { while ((read = in.read(buf)) > 0) { out.write(buf, 0, read); } - noException = true; - } - finally { - if(!noException) { - // Exception in progress - JOrphanUtils.closeQuietly(in); - } else { - in.close(); - } } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/Base64Encoder.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/Base64Encoder.java index 82fdf4ac8b2..6eecf175ff3 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/Base64Encoder.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/Base64Encoder.java @@ -37,6 +37,7 @@ public final class Base64Encoder { private Base64Encoder() { } + @SuppressWarnings("DefaultCharset") public static String encode(String s) { return encode(s.getBytes()); // TODO - charset? } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java index 1fc996cf250..a169220fe6e 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java @@ -195,8 +195,9 @@ public int parse(TestElement el, int parseCount) { return -1;// indicate that an error occurred } + @SuppressWarnings("DefaultCharset") private static BufferedReader getReader(File file) throws IOException { - if (! isGZIP(file)) { + if (!isGZIP(file)) { return new BufferedReader(new FileReader(file)); } GZIPInputStream in = new GZIPInputStream(new FileInputStream(file)); diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java index 96f37ebce73..2282216b1f3 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java @@ -464,7 +464,7 @@ private void setArgument(PreparedStatement pstmt, String argument, int targetSql case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: - pstmt.setBytes(index, argument.getBytes()); + pstmt.setBytes(index, argument.getBytes(StandardCharsets.UTF_8)); break; case Types.NULL: pstmt.setNull(index, targetSqlType); diff --git a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java index 7b00779ed9e..db95cd76617 100644 --- a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java +++ b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java @@ -87,12 +87,14 @@ public SampleResult sample(Entry e) { final String errCode = Integer.toString(ex.getErrorCode()); res.setResponseMessage(ex.toString()); res.setResponseCode(ex.getSQLState()+ " " +errCode); - res.setResponseData(ex.getMessage().getBytes()); + res.setResponseData(ex.getMessage(), res.getDataEncodingWithDefault()); res.setSuccessful(false); } catch (Exception ex) { res.setResponseMessage(ex.toString()); res.setResponseCode("000"); - res.setResponseData(ObjectUtils.defaultIfNull(ex.getMessage(), "NO MESSAGE").getBytes()); + res.setResponseData( + ObjectUtils.defaultIfNull(ex.getMessage(), "NO MESSAGE"), + res.getDataEncodingWithDefault()); res.setSuccessful(false); } finally { close(conn); diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java index 96d75899fc5..009e4cebfa1 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java @@ -223,7 +223,7 @@ private void handleBrowse(SampleResult res) throws JMSException { sb.append("Browse message on Send Queue ").append(sendQueue.getQueueName()) .append(": ") .append(browseQueueDetails(sendQueue, res)); - res.setResponseData(sb.toString().getBytes()); + res.setResponseData(sb.toString(), res.getDataEncodingWithDefault()); res.setResponseCodeOK(); } @@ -234,7 +234,7 @@ private void handleClearQueue(SampleResult res) throws JMSException { sb.append("Clear messages on Send Queue ").append(sendQueue.getQueueName()) .append(": ") .append(clearQueue(sendQueue, res)); - res.setResponseData(sb.toString().getBytes()); + res.setResponseData(sb.toString(), res.getDataEncodingWithDefault()); res.setResponseCodeOK(); } diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java index 21f1eecb826..371a541db95 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java @@ -195,7 +195,7 @@ public SampleResult sample() { } result.sampleEnd(); if (getReadResponseAsBoolean()) { - result.setResponseData(buffer.toString().getBytes()); // TODO - charset? + result.setResponseData(buffer.toString(), result.getDataEncodingWithDefault()); } else { result.setBytes((long)buffer.toString().length()); } diff --git a/src/protocol/mongodb/src/main/java/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptSampler.java b/src/protocol/mongodb/src/main/java/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptSampler.java index 4270b5eae54..be355628f97 100644 --- a/src/protocol/mongodb/src/main/java/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptSampler.java +++ b/src/protocol/mongodb/src/main/java/org/apache/jmeter/protocol/mongodb/sampler/MongoScriptSampler.java @@ -76,12 +76,12 @@ public SampleResult sample(Entry e) { Object result = runner.evaluate(db, data); EvalResultHandler handler = new EvalResultHandler(); String resultAsString = handler.handle(result); - res.setResponseData(resultAsString.getBytes()); + res.setResponseData(resultAsString, res.getDataEncodingWithDefault()); } catch (Exception ex) { res.setResponseCode("500"); // $NON-NLS-1$ res.setSuccessful(false); res.setResponseMessage(ex.toString()); - res.setResponseData(ex.getMessage().getBytes()); + res.setResponseData(ex.getMessage(), res.getDataEncodingWithDefault()); } finally { res.sampleEnd(); } diff --git a/src/protocol/native/src/main/java/org/apache/jmeter/protocol/system/SystemSampler.java b/src/protocol/native/src/main/java/org/apache/jmeter/protocol/system/SystemSampler.java index 850e17a99e3..c8b90ac6964 100644 --- a/src/protocol/native/src/main/java/org/apache/jmeter/protocol/system/SystemSampler.java +++ b/src/protocol/native/src/main/java/org/apache/jmeter/protocol/system/SystemSampler.java @@ -184,7 +184,9 @@ public SampleResult sample(Entry entry) { } if (nativeCommand != null) { - results.setResponseData(nativeCommand.getOutResult().getBytes()); // default charset is deliberate here + @SuppressWarnings("DefaultCharset") + final byte[] responseData = nativeCommand.getOutResult().getBytes(); + results.setResponseData(responseData); // default charset is deliberate here } return results; From e78352a8f72ad23a1b72da6b15f891fc48b8f7e5 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 19:40:58 +0300 Subject: [PATCH 21/40] Fix InconsistentCapitalization warnings --- .../main/java/org/apache/jmeter/config/CSVDataSet.java | 10 +++++----- .../org/apache/jmeter/engine/DistributedRunner.java | 10 +++++----- .../jmeter/util/HttpSSLProtocolSocketFactory.java | 9 ++++----- .../jmeter/protocol/http/util/accesslog/LogFilter.java | 1 + .../jmeter/protocol/http/util/accesslog/NVPair.java | 1 + .../http/util/accesslog/StandardGenerator.java | 1 + .../protocol/http/util/accesslog/TCLogParser.java | 1 + .../jmeter/protocol/java/sampler/JUnitSampler.java | 6 +++--- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java b/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java index dab31903eb0..f08a5f34f08 100644 --- a/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java +++ b/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java @@ -219,21 +219,21 @@ private void initVars(FileServer server, final JMeterContext context, String del trimVarNames(vars); } - private void setAlias(final JMeterContext context, String fileName) { + private void setAlias(final JMeterContext context, String alias) { String mode = getShareMode(); int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode); switch(modeInt){ case CSVDataSetBeanInfo.SHARE_ALL: - alias = fileName; + this.alias = alias; break; case CSVDataSetBeanInfo.SHARE_GROUP: - alias = fileName+"@"+System.identityHashCode(context.getThreadGroup()); + this.alias = alias + "@" + System.identityHashCode(context.getThreadGroup()); break; case CSVDataSetBeanInfo.SHARE_THREAD: - alias = fileName+"@"+System.identityHashCode(context.getThread()); + this.alias = alias + "@" + System.identityHashCode(context.getThread()); break; default: - alias = fileName+"@"+mode; // user-specified key + this.alias = alias + "@" + mode; // user-specified key break; } } diff --git a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java index b924799decc..e9c33eea93e 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java @@ -56,7 +56,7 @@ public class DistributedRunner { private final int retriesDelay; private final int retriesNumber; private PrintStream stdout = new PrintStream(new SilentOutputStream()); - private PrintStream stderr = new PrintStream(new SilentOutputStream()); + private PrintStream stdErr = new PrintStream(new SilentOutputStream()); private final Map engines = new HashMap<>(); @@ -249,13 +249,13 @@ private void println(String s) { private void errln(String s) { log.error(s); - stderr.println(s); + stdErr.println(s); } private void errln(String s, Exception e) { log.error(s, e); - stderr.println(s + ": "); - e.printStackTrace(stderr); // NOSONAR + stdErr.println(s + ": "); + e.printStackTrace(stdErr); // NOSONAR } public void setStdout(PrintStream stdout) { @@ -263,7 +263,7 @@ public void setStdout(PrintStream stdout) { } public void setStdErr(PrintStream stdErr) { - this.stderr = stdErr; + this.stdErr = stdErr; } private static class SilentOutputStream extends OutputStream { diff --git a/src/core/src/main/java/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java b/src/core/src/main/java/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java index af8f8c02ec0..9c5e927ee3a 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java +++ b/src/core/src/main/java/org/apache/jmeter/util/HttpSSLProtocolSocketFactory.java @@ -56,15 +56,14 @@ public class HttpSSLProtocolSocketFactory } } - private final int CPS; // Characters per second to emulate + private final int cps; // Characters per second to emulate public HttpSSLProtocolSocketFactory() { this(0); } public HttpSSLProtocolSocketFactory(int cps) { - super(); - CPS=cps; + this.cps = cps; } @@ -120,8 +119,8 @@ private SSLSocketFactory getSSLSocketFactory() throws IOException { * Wraps the socket in a slow SSL socket if necessary */ private Socket wrapSocket(Socket sock){ - if (CPS>0) { - return new SlowSSLSocket((SSLSocket) sock, CPS); + if (cps >0) { + return new SlowSSLSocket((SSLSocket) sock, cps); } return sock; } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java index 519caa3a901..5b9068088bb 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java @@ -67,6 +67,7 @@ * which will return null if it is filtered and replace any part of the string * that should be replaced. */ +@SuppressWarnings("InconsistentCapitalization") public class LogFilter implements Filter, Serializable { private static final long serialVersionUID = 241L; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/NVPair.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/NVPair.java index 08c9b20c6f1..59139386941 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/NVPair.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/NVPair.java @@ -23,6 +23,7 @@ * */ +@SuppressWarnings("InconsistentCapitalization") public class NVPair { protected String NAME = ""; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/StandardGenerator.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/StandardGenerator.java index a03c694f1c9..c66bce92419 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/StandardGenerator.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/StandardGenerator.java @@ -49,6 +49,7 @@ * added and should be left up to the user. One option is to provide parameters, * so the user can pass the desired listener to the tool. */ +@SuppressWarnings("InconsistentCapitalization") public class StandardGenerator implements Generator, Serializable { private static final long serialVersionUID = 234L; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java index a169220fe6e..ee9770a929e 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java @@ -71,6 +71,7 @@ * IIS and Netscape. */ +@SuppressWarnings("InconsistentCapitalization") public class TCLogParser implements LogParser { protected static final Logger log = LoggerFactory.getLogger(TCLogParser.class); diff --git a/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java b/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java index 09eb2f6176a..3ffc8fa957f 100644 --- a/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java +++ b/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java @@ -121,12 +121,12 @@ private void initMethodObjects(Object testObject){ /** * Sets the Classname attribute of the JavaConfig object * - * @param classname + * @param className * the new Classname value */ - public void setClassname(String classname) + public void setClassname(String className) { - setProperty(CLASSNAME, classname); + setProperty(CLASSNAME, className); } /** From 369f65147f98f04a80faa37c898d5a120c850d3e Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 19:55:49 +0300 Subject: [PATCH 22/40] Suppress JdkObsolete warnings for Enumeration In all the cases Enumeration comes from Java interfaces, so we can't avoid it. Unfortunately error-prone does not recognize that yet. See https://github.com/google/error-prone/issues/1646 --- .../main/java/org/apache/jmeter/control/ModuleController.java | 2 ++ .../main/java/org/apache/jmeter/visualizers/RenderAsXML.java | 1 + src/core/src/main/java/org/apache/jmeter/JMeter.java | 1 + .../org/apache/jmeter/gui/action/ApplyNamingConvention.java | 1 + .../org/apache/jmeter/gui/action/CollapseExpandTreeBranch.java | 1 + src/core/src/main/java/org/apache/jmeter/gui/action/Copy.java | 1 + .../main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java | 3 +++ .../org/apache/jmeter/gui/tree/JMeterTreeTransferHandler.java | 1 + .../java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java | 3 +++ .../apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java | 1 + src/core/src/main/java/org/apache/jmeter/util/NameUpdater.java | 1 + .../java/org/apache/jmeter/util/keystore/JmeterKeyStore.java | 1 + .../org/apache/jmeter/protocol/jms/sampler/JMSSampler.java | 2 ++ .../apache/jmeter/protocol/jms/sampler/SubscriberSampler.java | 1 + .../org/apache/jmeter/protocol/java/sampler/JUnitSampler.java | 1 + .../apache/jmeter/protocol/mail/sampler/MailReaderSampler.java | 2 ++ .../org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java | 1 + 17 files changed, 24 insertions(+) diff --git a/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java b/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java index d46c16ffad9..6bf5fe369f5 100644 --- a/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java +++ b/src/components/src/main/java/org/apache/jmeter/control/ModuleController.java @@ -192,6 +192,7 @@ public HashTree getReplacementSubTree() { return tree; } + @SuppressWarnings("JdkObsolete") private void createSubTree(HashTree tree, JMeterTreeNode node) { Enumeration e = node.children(); while (e.hasMoreElements()) { @@ -208,6 +209,7 @@ private static JMeterTreeNode cloneTreeNode(JMeterTreeNode node) { return treeNode; } + @SuppressWarnings("JdkObsolete") private static void cloneChildren(JMeterTreeNode to, JMeterTreeNode from) { Enumeration enumr = from.children(); while (enumr.hasMoreElements()) { diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java index 5ae7cd077df..8717fc7cd13 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RenderAsXML.java @@ -148,6 +148,7 @@ private void expandAll(TreePath parent) { tree.expandPath(parent); } + @SuppressWarnings("JdkObsolete") private void applyToChildren(TreePath parent, Consumer method) { TreeNode node = (TreeNode) parent.getLastPathComponent(); Enumeration e = node.children(); diff --git a/src/core/src/main/java/org/apache/jmeter/JMeter.java b/src/core/src/main/java/org/apache/jmeter/JMeter.java index 0d1626d0101..6ed0003b879 100644 --- a/src/core/src/main/java/org/apache/jmeter/JMeter.java +++ b/src/core/src/main/java/org/apache/jmeter/JMeter.java @@ -1391,6 +1391,7 @@ private static void println(String str) { } @Override + @SuppressWarnings("JdkObsolete") public String[][] getIconMappings() { final String defaultIconProp = "org/apache/jmeter/images/icon.properties"; //$NON-NLS-1$ final String iconSize = JMeterUtils.getPropDefault(TREE_ICON_SIZE, DEFAULT_TREE_ICON_SIZE); diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/ApplyNamingConvention.java b/src/core/src/main/java/org/apache/jmeter/gui/action/ApplyNamingConvention.java index 761b6e709a4..3721ddd974e 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/ApplyNamingConvention.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/ApplyNamingConvention.java @@ -79,6 +79,7 @@ public void doAction(ActionEvent e) { * @param guiPackage {@link GuiPackage} * @param currentNode Parent node of elements on which we apply naming policy */ + @SuppressWarnings("JdkObsolete") private void applyNamingPolicyToCurrentNode(GuiPackage guiPackage, JMeterTreeNode currentNode) { TreeNodeNamingPolicy namingPolicy = guiPackage.getNamingPolicy(); diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/CollapseExpandTreeBranch.java b/src/core/src/main/java/org/apache/jmeter/gui/action/CollapseExpandTreeBranch.java index 6ce917487de..11460ba3341 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/CollapseExpandTreeBranch.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/CollapseExpandTreeBranch.java @@ -78,6 +78,7 @@ public void doAction(ActionEvent e) { } } + @SuppressWarnings("JdkObsolete") private void expandCollapseNode(JTree jTree, TreePath parent, boolean collapse) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.isLeaf()) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/Copy.java b/src/core/src/main/java/org/apache/jmeter/gui/action/Copy.java index d2cc765990a..96165d07d74 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/Copy.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/Copy.java @@ -134,6 +134,7 @@ public static JMeterTreeNode[] cloneTreeNodes(JMeterTreeNode[] nodes) { return treeNodes; } + @SuppressWarnings("JdkObsolete") private static void cloneChildren(JMeterTreeNode to, JMeterTreeNode from) { Enumeration enumFrom = from.children(); while (enumFrom.hasMoreElements()) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java index c64de1f50b0..16cc5ddc9a2 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeModel.java @@ -184,6 +184,7 @@ public void removeNodeFromParent(JMeterTreeNode node) { } } + @SuppressWarnings("JdkObsolete") private void traverseAndFind(Class type, JMeterTreeNode node, List nodeList) { if (type.isInstance(node.getUserObject())) { nodeList.add(node); @@ -195,6 +196,7 @@ private void traverseAndFind(Class type, JMeterTreeNode node, List enumNode = node.children(); diff --git a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeTransferHandler.java b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeTransferHandler.java index 7b779f68efd..3990f4a1c41 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeTransferHandler.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeTransferHandler.java @@ -190,6 +190,7 @@ public boolean canImport(TransferHandler.TransferSupport support) { } @Override + @SuppressWarnings("JdkObsolete") public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java index 36e29066160..172f4d6f5c5 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JLabeledRadioI18N.java @@ -125,6 +125,7 @@ private void initButtonGroup(String[] resources, String selected) { * @param selected initially selected resource (if not null) * */ + @SuppressWarnings("JdkObsolete") public void resetButtons(String[] resources, String selected) { Enumeration buttons = bGroup.getElements(); List buttonsToRemove = new ArrayList<>(this.bGroup.getButtonCount()); @@ -159,6 +160,7 @@ public String getText() { * @param resourceName name of resource whose button is to be selected */ @Override + @SuppressWarnings("JdkObsolete") public void setText(String resourceName) { Enumeration en = this.bGroup.getElements(); while (en.hasMoreElements()) { @@ -203,6 +205,7 @@ private void notifyChangeListeners() { * excluded from the list. */ @Override + @SuppressWarnings("JdkObsolete") public List getComponentList() { List comps = new ArrayList<>(); comps.add(mLabel); diff --git a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java index b3c647b007b..25ee55cfb53 100644 --- a/src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java +++ b/src/core/src/main/java/org/apache/jmeter/testbeans/gui/GenericTestBeanCustomizer.java @@ -316,6 +316,7 @@ public GenericTestBeanCustomizer(){ * @param pd the descriptor * @param pe the propertyEditor */ + @SuppressWarnings("JdkObsolete") private static void validateAttributes(PropertyDescriptor pd, PropertyEditor pe) { final Object deflt = pd.getValue(DEFAULT); if (deflt == null) { diff --git a/src/core/src/main/java/org/apache/jmeter/util/NameUpdater.java b/src/core/src/main/java/org/apache/jmeter/util/NameUpdater.java index b63d255fcc3..3f0e2e77bd8 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/NameUpdater.java +++ b/src/core/src/main/java/org/apache/jmeter/util/NameUpdater.java @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@SuppressWarnings("JdkObsolete") public final class NameUpdater { private static final Properties nameMap; // Read-only access after class has been initialised diff --git a/src/core/src/main/java/org/apache/jmeter/util/keystore/JmeterKeyStore.java b/src/core/src/main/java/org/apache/jmeter/util/keystore/JmeterKeyStore.java index e1ab1f8bba6..5a3afdf8a18 100644 --- a/src/core/src/main/java/org/apache/jmeter/util/keystore/JmeterKeyStore.java +++ b/src/core/src/main/java/org/apache/jmeter/util/keystore/JmeterKeyStore.java @@ -102,6 +102,7 @@ private JmeterKeyStore(String type, int startIndex, int endIndex, String clientC * @throws UnrecoverableKeyException if the key can not be recovered from the store (should not * happen here, either) */ + @SuppressWarnings("JdkObsolete") public void load(InputStream is, String pword) throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException, UnrecoverableKeyException { char[] pw = toCharArrayOrNull(pword); diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java index 009e4cebfa1..06be8133765 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java @@ -350,6 +350,7 @@ private String browseQueueForConsumption(Queue queue, return retVal; } + @SuppressWarnings("JdkObsolete") private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg) { if (msg != null) { try { @@ -388,6 +389,7 @@ private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Mess } } + @SuppressWarnings("JdkObsolete") private String browseQueueDetails(Queue queue, SampleResult res) { String queueName = null; try { diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java index 371a541db95..babf208b33c 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java @@ -274,6 +274,7 @@ private long calculateWait(long until, long now) { return wait > DEFAULT_WAIT ? DEFAULT_WAIT : wait; } + @SuppressWarnings("JdkObsolete") private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) { if (msg != null) { diff --git a/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java b/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java index 3ffc8fa957f..ace57695c0a 100644 --- a/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java +++ b/src/protocol/junit/src/main/java/org/apache/jmeter/protocol/java/sampler/JUnitSampler.java @@ -366,6 +366,7 @@ public void setJunit4(boolean junit4) { /** {@inheritDoc} */ @Override + @SuppressWarnings("JdkObsolete") public SampleResult sample(Entry entry) { if(getCreateOneInstancePerSample()) { initializeTestObject(); diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java index 09ba1c79e7c..50ceed04e0e 100644 --- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java +++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailReaderSampler.java @@ -139,6 +139,7 @@ public MailReaderSampler() { * {@inheritDoc} */ @Override + @SuppressWarnings("JdkObsolete") public SampleResult sample(Entry e) { SampleResult parent = new SampleResult(); boolean isOK = false; // Did sample succeed? @@ -305,6 +306,7 @@ public SampleResult sample(Entry e) { return parent; } + @SuppressWarnings("JdkObsolete") protected void addCustomProperties(Properties props) { Properties jMeterProperties = JMeterUtils.getJMeterProperties(); @SuppressWarnings("unchecked") diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java index 5566f9f5645..70697b5ac35 100644 --- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java +++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java @@ -329,6 +329,7 @@ private String getSamplerData(Message message) throws MessagingException, IOExce return sb.toString(); } + @SuppressWarnings("JdkObsolete") private void writeHeaders(Enumeration
    headers, StringBuilder sb) { while (headers.hasMoreElements()) { Header header = headers.nextElement(); From deb89ba3d1f9c5d790d27ba58764d8899f37f6ad Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:01:47 +0300 Subject: [PATCH 23/40] Remove unused variables --- .../jmeter/extractor/json/jmespath/JMESPathExtractor.java | 3 +-- .../poissonarrivals/ConstantPoissonProcessGenerator.java | 2 ++ .../org/apache/jmeter/gui/action/LookAndFeelCommand.java | 5 ----- .../jmeter/report/processor/graph/AbstractGraphConsumer.java | 3 ++- .../src/main/java/org/apache/jmeter/functions/XPath.java | 4 +--- .../jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java | 4 ---- .../apache/jmeter/protocol/http/parser/HtmlParsingUtils.java | 2 +- .../jmeter/protocol/http/util/GraphQLRequestParamUtils.java | 2 +- .../jmeter/protocol/http/util/accesslog/TCLogParser.java | 2 +- 9 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/json/jmespath/JMESPathExtractor.java b/src/components/src/main/java/org/apache/jmeter/extractor/json/jmespath/JMESPathExtractor.java index abff458bbd1..2c646579c7c 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/json/jmespath/JMESPathExtractor.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/json/jmespath/JMESPathExtractor.java @@ -72,9 +72,8 @@ public void process() { } try { - JsonNode result = null; JsonNode actualObj = OBJECT_MAPPER.readValue(jsonResponse, JsonNode.class); - result = JMESPathCache.getInstance().get(jsonPathExpression).search(actualObj); + JsonNode result = JMESPathCache.getInstance().get(jsonPathExpression).search(actualObj); if (result.isNull()) { handleNullResult(vars, refName, defaultValue, matchNumber); return; diff --git a/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java b/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java index 7205e797679..14151f0e7b8 100644 --- a/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java +++ b/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/ConstantPoissonProcessGenerator.java @@ -37,6 +37,8 @@ public class ConstantPoissonProcessGenerator implements EventProducer { private final Random rnd = new Random(); private final ThroughputProvider throughputProvider; private final int batchSize; + // TODO: implement + @SuppressWarnings("unused") private final int batchThreadDelay; private final DurationProvider durationProvider; private final boolean logFirstSamples; diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java b/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java index e30dc5591cc..0c1cf104da5 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/LookAndFeelCommand.java @@ -35,8 +35,6 @@ import org.apache.jmeter.gui.util.JMeterMenuBar; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.gui.JFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.theme.DarculaTheme; @@ -46,9 +44,6 @@ * Implements the Look and Feel menu item. */ public class LookAndFeelCommand extends AbstractAction { - - private static final Logger log = LoggerFactory.getLogger(LookAndFeelCommand.class); - private static final String JMETER_LAF = "jmeter.laf"; // $NON-NLS-1$ private static final Map items = new LinkedHashMap<>(); diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphConsumer.java b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphConsumer.java index 2e0f145dfe2..2708e73a11a 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphConsumer.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/AbstractGraphConsumer.java @@ -237,7 +237,8 @@ private void setMaxResult(MapResultData result, String name, Double value) { * @param seriesData * @param aggregated */ - private void addKeyData(MapResultData result, String group, String series, + private void addKeyData(MapResultData result, @SuppressWarnings("unused") String group, + String series, SeriesData seriesData, boolean aggregated) { // Override series name when aggregated diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java b/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java index 6c1f60aa95b..1200ccc55a1 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/XPath.java @@ -66,14 +66,12 @@ public XPath() { @Override public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { - String myValue = ""; //$NON-NLS-1$ - String fileName = ((CompoundVariable) values[0]).execute(); String xpathString = ((CompoundVariable) values[1]).execute(); log.debug("execute ({} {})", fileName, xpathString); - myValue = XPathWrapper.getXPathString(fileName, xpathString); + String myValue = XPathWrapper.getXPathString(fileName, xpathString); log.debug("execute value: {}", myValue); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java index 38b382403e8..7c0462a148f 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/GraphQLUrlConfigGui.java @@ -37,8 +37,6 @@ import org.apache.jmeter.testelement.property.TestElementProperty; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.gui.JLabeledTextField; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Extending {@link UrlConfigGui}, GraphQL over HTTP Request configuration GUI, providing more convenient UI elements @@ -48,8 +46,6 @@ public class GraphQLUrlConfigGui extends UrlConfigGui { private static final long serialVersionUID = 1L; - private static Logger log = LoggerFactory.getLogger(GraphQLUrlConfigGui.class); - public static final String OPERATION_NAME = "GraphQLHTTPSampler.operationName"; public static final String QUERY = "GraphQLHTTPSampler.query"; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java index 2b3fbb8fa17..d692b02c073 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/parser/HtmlParsingUtils.java @@ -381,7 +381,7 @@ public static void extractStyleURLs(final URL baseUrl, final URLCollection urls, Pattern pattern = JMeterUtils.getPatternCache().getPattern( "URL\\(\\s*('|\")(.*)('|\")\\s*\\)", // $NON-NLS-1$ Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK | Perl5Compiler.READ_ONLY_MASK); - PatternMatcherInput input = null; + PatternMatcherInput input; input = new PatternMatcherInput(styleTagStr); while (matcher.contains(input, pattern)) { MatchResult match = matcher.getMatch(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java index fd387cff6a9..0d3f7422079 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java @@ -155,7 +155,7 @@ public static GraphQLRequestParams toGraphQLRequestParams(byte[] postData, final } String operationName = null; - String query = null; + String query; String variables = null; final JsonNode operationNameNode = data.has(OPERATION_NAME_FIELD) ? data.get(OPERATION_NAME_FIELD) : null; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java index ee9770a929e..ce79dd0bab9 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java @@ -314,7 +314,7 @@ protected int parseLine(String line, TestElement el) { * @param el {@link TestElement} into which the url will be added */ private void createUrl(String line, TestElement el) { - String paramString = null; + String paramString; // check the URL for "?" symbol paramString = this.stripFile(line, el); if (paramString != null) { From 3d133a8840703b3b2c6871115f3b10ecebcb7944 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:08:35 +0300 Subject: [PATCH 24/40] Suppress JdkObsolete warnings for usages of Date It would be nice to migrate to java.time API, so the idea is to suppress the current usages, and use newer APIs for the new code. --- .../apache/jmeter/visualizers/RespTimeGraphVisualizer.java | 1 + .../org/apache/jmeter/visualizers/SamplerResultTab.java | 2 +- src/core/src/main/java/org/apache/jmeter/JMeter.java | 5 ++++- .../java/org/apache/jmeter/engine/DistributedRunner.java | 1 + .../java/org/apache/jmeter/engine/StandardJMeterEngine.java | 2 ++ .../main/java/org/apache/jmeter/gui/util/JDateField.java | 2 ++ .../main/java/org/apache/jmeter/report/core/TimeHelper.java | 1 + .../org/apache/jmeter/report/dashboard/ReportGenerator.java | 1 + .../jmeter/report/processor/NormalizerSampleConsumer.java | 1 + .../main/java/org/apache/jmeter/reporters/ResultSaver.java | 1 + .../main/java/org/apache/jmeter/save/CSVSaveService.java | 2 ++ .../src/main/java/org/apache/jmeter/visualizers/Sample.java | 1 + .../java/org/apache/jmeter/visualizers/TableSample.java | 1 + .../apache/jmeter/functions/DateTimeConvertFunction.java | 1 + .../main/java/org/apache/jmeter/functions/TimeFunction.java | 1 + .../apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java | 1 + .../org/apache/jmeter/protocol/jms/sampler/JMSSampler.java | 6 +++++- 17 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java index 405e504212f..03115a2ce90 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java @@ -705,6 +705,7 @@ private JPanel createGraphActionsPane() { return buttonPanel; } + @SuppressWarnings("JdkObsolete") public String[] getXAxisLabels() { SimpleDateFormat formatter = new SimpleDateFormat(xAxisTimeFormat.getText()); //$NON-NLS-1$ String[] xAxisLabels = new String[(int) durationTest]; // Test can't have a duration more than 2^31 secs (cast from long to int) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java index 0a4f6d6fe12..3828c2a571d 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java @@ -225,7 +225,7 @@ public void init() { } @Override - @SuppressWarnings("boxing") + @SuppressWarnings({"boxing", "JdkObsolete"}) public void setupTabPane() { // Clear all data before display a new this.clearData(); diff --git a/src/core/src/main/java/org/apache/jmeter/JMeter.java b/src/core/src/main/java/org/apache/jmeter/JMeter.java index 6ed0003b879..5bf66de6852 100644 --- a/src/core/src/main/java/org/apache/jmeter/JMeter.java +++ b/src/core/src/main/java/org/apache/jmeter/JMeter.java @@ -449,6 +449,7 @@ private void startGui(String testFile) { * Called reflectively by {@link NewDriver#main(String[])} * @param args The arguments for JMeter */ + @SuppressWarnings("JdkObsolete") public void start(String[] args) { CLArgsParser parser = new CLArgsParser(args, options); String error = parser.getErrorString(); @@ -1007,7 +1008,8 @@ private void startNonGui(String testFile, String logFile, CLOption remoteStart, } // run test in batch mode - void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString, boolean generateReportDashboard) + @SuppressWarnings("JdkObsolete") + void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString, boolean generateReportDashboard) throws ConfigurationException { try { File f = new File(testFile); @@ -1313,6 +1315,7 @@ public void testStarted() { } } + @SuppressWarnings("JdkObsolete") private void endTest(boolean isDistributed) { long now = System.currentTimeMillis(); if (isDistributed) { diff --git a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java index e9c33eea93e..5ed86cbfc90 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/DistributedRunner.java @@ -121,6 +121,7 @@ public void init(List addresses, HashTree tree) { * * @param addresses list of the DNS names or IP addresses of the remote testing engines */ + @SuppressWarnings("JdkObsolete") public void start(List addresses) { long now = System.currentTimeMillis(); println("Starting distributed test with remote engines: " + addresses + " @ " + new Date(now) + " (" + now + ")"); diff --git a/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java b/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java index d4df3ef668e..aa1aae664bd 100644 --- a/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java +++ b/src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java @@ -171,6 +171,7 @@ public void configure(HashTree testTree) { } @Override + @SuppressWarnings("JdkObsolete") public void runTest() throws JMeterEngineException { if (host != null){ long now=System.currentTimeMillis(); @@ -208,6 +209,7 @@ private void notifyTestListenersOfStart(SearchByClass testLis } } + @SuppressWarnings("JdkObsolete") private void notifyTestListenersOfEnd(SearchByClass testListeners) { log.info("Notifying test listeners of end of test"); for (TestStateListener tl : testListeners.getSearchResults()) { diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JDateField.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JDateField.java index 35f6e92e8bf..813310b1a91 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JDateField.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JDateField.java @@ -93,6 +93,7 @@ public JDateField(Date date) { } // Dummy constructor to allow JUnit tests to work + @SuppressWarnings("JdkObsolete") public JDateField() { this(new Date()); } @@ -112,6 +113,7 @@ public void setDate(Date date) { * * @return The currently set date */ + @SuppressWarnings("JdkObsolete") public Date getDate() { try { return dateFormat.parse(getText()); diff --git a/src/core/src/main/java/org/apache/jmeter/report/core/TimeHelper.java b/src/core/src/main/java/org/apache/jmeter/report/core/TimeHelper.java index 6a298b61b76..b490b48dea6 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/core/TimeHelper.java +++ b/src/core/src/main/java/org/apache/jmeter/report/core/TimeHelper.java @@ -76,6 +76,7 @@ public static String formatTimeStamp(long timeStamp) { * the format * @return the string */ + @SuppressWarnings("JdkObsolete") public static String formatTimeStamp(long timeStamp, String format) { SimpleDateFormat dateFormat = format != null ? new SimpleDateFormat( format) : new SimpleDateFormat(); diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java index 70bda7235d4..1e2625f9740 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java @@ -268,6 +268,7 @@ public void generate() throws GenerationException { /** * @return {@link FilterConsumer} that filter data based on date range */ + @SuppressWarnings("JdkObsolete") private FilterConsumer createFilterByDateRange() { FilterConsumer dateRangeFilter = new FilterConsumer(); dateRangeFilter.setName(DATE_RANGE_FILTER_CONSUMER_NAME); diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java b/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java index c5f3fff5a12..4fd85293dee 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java @@ -92,6 +92,7 @@ private SimpleDateFormat createFormatter() { } @Override + @SuppressWarnings("JdkObsolete") public void consume(Sample s, int channel) { Date date = null; try { diff --git a/src/core/src/main/java/org/apache/jmeter/reporters/ResultSaver.java b/src/core/src/main/java/org/apache/jmeter/reporters/ResultSaver.java index 55191f52297..b1f0c55977c 100644 --- a/src/core/src/main/java/org/apache/jmeter/reporters/ResultSaver.java +++ b/src/core/src/main/java/org/apache/jmeter/reporters/ResultSaver.java @@ -123,6 +123,7 @@ public void testStarted() { } @Override + @SuppressWarnings("JdkObsolete") public void testStarted(String host) { synchronized(LOCK){ sequenceNumber = 0; diff --git a/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java b/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java index 72015831409..2f21dc56e1a 100644 --- a/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java +++ b/src/core/src/main/java/org/apache/jmeter/save/CSVSaveService.java @@ -191,6 +191,7 @@ public static void processSamples(String filename, Visualizer visualizer, * * @throws JMeterError */ + @SuppressWarnings("JdkObsolete") private static SampleEvent makeResultFromDelimitedString( final String[] parts, final SampleSaveConfiguration saveConfig, // may be updated @@ -809,6 +810,7 @@ public static String resultToDelimitedString(SampleEvent event, * the separation string * @return the separated value representation of the result */ + @SuppressWarnings("JdkObsolete") public static String resultToDelimitedString(SampleEvent event, SampleResult sample, SampleSaveConfiguration saveConfig, diff --git a/src/core/src/main/java/org/apache/jmeter/visualizers/Sample.java b/src/core/src/main/java/org/apache/jmeter/visualizers/Sample.java index 0240bf9c6dc..bb0fec28456 100644 --- a/src/core/src/main/java/org/apache/jmeter/visualizers/Sample.java +++ b/src/core/src/main/java/org/apache/jmeter/visualizers/Sample.java @@ -208,6 +208,7 @@ public long getStartTime() { * @return the start time using the specified format * Intended for use from Functors */ + @SuppressWarnings("JdkObsolete") public String getStartTimeFormatted(Format format) { return format.format(new Date(getStartTime())); } diff --git a/src/core/src/main/java/org/apache/jmeter/visualizers/TableSample.java b/src/core/src/main/java/org/apache/jmeter/visualizers/TableSample.java index 5488ada5f2b..9c7f62efc42 100644 --- a/src/core/src/main/java/org/apache/jmeter/visualizers/TableSample.java +++ b/src/core/src/main/java/org/apache/jmeter/visualizers/TableSample.java @@ -107,6 +107,7 @@ public long getStartTime() { * @return the start time using the specified format * Intended for use from Functors */ + @SuppressWarnings("JdkObsolete") public String getStartTimeFormatted(Format format) { return format.format(new Date(getStartTime())); } diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java index fb80f3a3cbf..002d795f66b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/DateTimeConvertFunction.java @@ -62,6 +62,7 @@ public List getArgumentDesc() { } @Override + @SuppressWarnings("JdkObsolete") public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { String dateString = values[0].execute(); String sourceDateFormat = values[1].execute(); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java b/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java index fa9462f5f9c..e6566a205fd 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/TimeFunction.java @@ -77,6 +77,7 @@ public TimeFunction(){ /** {@inheritDoc} */ @Override + @SuppressWarnings("JdkObsolete") public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { String datetime; if (format.length() == 0){// Default to milliseconds diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java index f9d91f28bd5..9e60decdf3a 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java @@ -337,6 +337,7 @@ public boolean isDestinationStatic(){ * @param message JMS Message * @return String with message header values. */ + @SuppressWarnings("JdkObsolete") public static String getMessageHeaders(Message message) { final StringBuilder response = new StringBuilder(256); try { diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java index 06be8133765..d10710b4609 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java @@ -745,6 +745,7 @@ private void printEnvironment(Context context) throws NamingException { } } + @SuppressWarnings("JdkObsolete") private void logThreadStart() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Thread started {}", new Date()); @@ -791,8 +792,11 @@ public String getPriority() { * {@inheritDoc} */ @Override + @SuppressWarnings("JdkObsolete") public void threadFinished() { - LOGGER.debug("Thread ended {}", new Date()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Thread ended {}", new Date()); + } if (context != null) { try { From 5f84f1e68126dc23c154baedb165861dca64a1b7 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:10:27 +0300 Subject: [PATCH 25/40] Add missing @Override annotations --- .../jmeter/extractor/json/render/RenderAsJsonRenderer.java | 1 + .../jmeter/timers/poissonarrivals/PreciseThroughputTimer.java | 2 ++ .../org/apache/jmeter/gui/action/template/TemplateManager.java | 1 + .../org/apache/jmeter/threads/UnmodifiableJMeterVariables.java | 1 + 4 files changed, 5 insertions(+) diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java index 8c3de95fb9c..5536b29ac04 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJsonRenderer.java @@ -46,6 +46,7 @@ protected String getExpressionLabel() { return JMeterUtils.getResString("jsonpath_tester_field"); } + @Override protected String process(String textToParse) { String expression = getExpression(); try { diff --git a/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimer.java b/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimer.java index 4d482b107de..48a6a75233d 100644 --- a/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimer.java +++ b/src/components/src/main/java/org/apache/jmeter/timers/poissonarrivals/PreciseThroughputTimer.java @@ -145,6 +145,7 @@ private EventProducer getEventProducer() { * Returns number of generated samples per {@link #getThroughputPeriod} * @return number of samples per {@link #getThroughputPeriod} */ + @Override public double getThroughput() { return throughput; } @@ -170,6 +171,7 @@ public void setThroughputPeriod(int throughputPeriod) { this.throughputPeriod = throughputPeriod; } + @Override public long getDuration() { return duration; } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/template/TemplateManager.java b/src/core/src/main/java/org/apache/jmeter/gui/action/template/TemplateManager.java index 2e516568f41..046ffba8f77 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/template/TemplateManager.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/template/TemplateManager.java @@ -152,6 +152,7 @@ public DefaultEntityResolver() { super(); } + @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if(systemId.endsWith("templates.dtd")) { return new InputSource(TemplateManager.class.getResourceAsStream("/org/apache/jmeter/gui/action/template/templates.dtd")); diff --git a/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java b/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java index cdd24deb3d8..3e77e91fb4f 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java @@ -128,6 +128,7 @@ public Set> entrySet() { return variables.entrySet(); } + @Override public String toString() { return variables.toString(); } From b1255aa0869822420cf01c5eb204a3489d0a7825 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:13:44 +0300 Subject: [PATCH 26/40] Mark empty catch blocks with a comment error-prone requires the comment --- .../org/apache/jmeter/testelement/property/NumberProperty.java | 1 + .../src/main/java/org/apache/jorphan/util/Converter.java | 1 + .../apache/jmeter/protocol/http/control/HttpMirrorServer.java | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java b/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java index 2eeb12c0f24..f2f4bac1dec 100644 --- a/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java +++ b/src/core/src/main/java/org/apache/jmeter/testelement/property/NumberProperty.java @@ -54,6 +54,7 @@ public void setObjectValue(Object v) { try { setNumberValue(v.toString()); } catch (RuntimeException ignored) { + // Intentionally left blank } } } diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/Converter.java b/src/jorphan/src/main/java/org/apache/jorphan/util/Converter.java index 86b1004cb24..cf24b5d141e 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/Converter.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/Converter.java @@ -70,6 +70,7 @@ public static Object convert(Object value, Class toType) { try { convertedValue = Class.forName(value.toString()); } catch (Exception ignored) { + // Intentionally left blank } } return convertedValue; diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java index 724ba1795c3..7b69733fd9c 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/control/HttpMirrorServer.java @@ -228,11 +228,13 @@ private static int getHttpPort(String[] args, CLArgsParser parser) { try { port = Integer.parseInt(value); } catch (NumberFormatException ignored) { + // Intentionally left blank } } else if (args.length > 0) { try { port = Integer.parseInt(args[0]); } catch (NumberFormatException ignored) { + // Intentionally left blank } } return port; From d756670086b12e890400dafcbedfda3c53e08171 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:30:02 +0300 Subject: [PATCH 27/40] Suppress FutureReturnValueIgnored Most of the times, the returned Future objects must not be ignored. DiskStoreSampleSender should probably be reworked to propagate exceptions. --- .../jmeter/samplers/DiskStoreSampleSender.java | 3 +++ .../protocol/http/sampler/ResourcesDownloader.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/samplers/DiskStoreSampleSender.java b/src/core/src/main/java/org/apache/jmeter/samplers/DiskStoreSampleSender.java index 537c3489997..eec4da61312 100644 --- a/src/core/src/main/java/org/apache/jmeter/samplers/DiskStoreSampleSender.java +++ b/src/core/src/main/java/org/apache/jmeter/samplers/DiskStoreSampleSender.java @@ -67,6 +67,7 @@ public DiskStoreSampleSender(){ } @Override + @SuppressWarnings("FutureReturnValueIgnored") public void testEnded(String host) { log.info("Test Ended on {}", host); singleExecutor.submit(() -> { @@ -121,6 +122,7 @@ public void testEnded(String host) { } @Override + @SuppressWarnings("FutureReturnValueIgnored") public void sampleOccurred(final SampleEvent e) { // sampleOccurred is called from multiple threads; not safe to write from multiple threads. // also decouples the file IO from sample generation @@ -141,6 +143,7 @@ public void sampleOccurred(final SampleEvent e) { * never */ // TODO should errors be thrown back through RMI? + @SuppressWarnings("FutureReturnValueIgnored") private Object readResolve() throws ObjectStreamException{ log.info("Using DiskStoreSampleSender for this test run"); // server log file singleExecutor = Executors.newSingleThreadExecutor(); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/ResourcesDownloader.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/ResourcesDownloader.java index 1cbdeac3056..938e10114f1 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/ResourcesDownloader.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/ResourcesDownloader.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.Future; import java.util.concurrent.SynchronousQueue; @@ -175,7 +176,11 @@ public List> invokeAllAndAwaitTermination( // wait for a previous download to finish before submitting a new one for (; i < list.size(); i++) { Callable task = list.get(i); - completionService.take(); + try { + completionService.take().get(); + } catch (ExecutionException e) { + throw new RuntimeException("Task execution failed", e.getCause()); + } remainingTasksToTake--; submittedTasks.add(completionService.submit(task)); } @@ -183,7 +188,11 @@ public List> invokeAllAndAwaitTermination( // all the resources downloads are in the thread pool queue // wait for the completion of all downloads while (remainingTasksToTake > 0) { - completionService.take(); + try { + completionService.take().get(); + } catch (ExecutionException e) { + throw new RuntimeException("Task execution failed", e.getCause()); + } remainingTasksToTake--; } } finally { From bb3463271a8bdd4b97736cff4181c3ad5eaf7b39 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:51:15 +0300 Subject: [PATCH 28/40] Suppress Thread.yield usage --- .../org/apache/jmeter/visualizers/backend/BackendListener.java | 1 - .../jmeter/protocol/http/util/accesslog/SessionFilter.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListener.java b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListener.java index 5b596770d29..4842f923ba2 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListener.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/backend/BackendListener.java @@ -399,7 +399,6 @@ static class ErrorBackendListenerClient extends AbstractBackendListenerClient { @Override public void handleSampleResults(List sampleResults, BackendListenerContext context) { log.warn("ErrorBackendListenerClient#handleSampleResult called, noop"); - Thread.yield(); } } diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java index 440db427747..b22167b0d66 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java @@ -160,6 +160,7 @@ public boolean isFiltered(String path,TestElement sampler) { return false; } + @SuppressWarnings("ThreadPriorityCheck") protected CookieManager getCookieManager(String ipAddr) { CookieManager cm; From c441e5b4586f872cb4674242e594b7b3b3e95069 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 20:52:04 +0300 Subject: [PATCH 29/40] Suppress JavaTimeDefaultTimeZone --- .../apache/jmeter/functions/RandomDate.java | 2 ++ .../apache/jmeter/functions/TimeShift.java | 3 +++ .../gui/action/ParseCurlCommandAction.java | 26 +++++++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/RandomDate.java b/src/functions/src/main/java/org/apache/jmeter/functions/RandomDate.java index a3d85adaabf..79d17913d7b 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/RandomDate.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/RandomDate.java @@ -202,9 +202,11 @@ public String execute(SampleResult previousResult, Sampler currentSampler) throw return dateString; } + @SuppressWarnings("JavaTimeDefaultTimeZone") private DateTimeFormatter createFormatter(LocaleFormatObject format) { log.debug("Create a new instance of DateTimeFormatter for format '{}' in the cache", format); return new DateTimeFormatterBuilder().appendPattern(format.getFormat()) + // TODO: what if year changes? (e.g. the year changes as the test executes) .parseDefaulting(ChronoField.DAY_OF_MONTH, 1).parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) .parseDefaulting(ChronoField.YEAR_OF_ERA, Year.now().getValue()).toFormatter(format.getLocale()); diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java b/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java index 2a321b0590c..c7e3a2709fe 100644 --- a/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java +++ b/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java @@ -197,6 +197,7 @@ public String execute(SampleResult previousResult, Sampler currentSampler) throw return dateString; } + @SuppressWarnings("JavaTimeDefaultTimeZone") private DateTimeFormatter createFormatter(LocaleFormatObject format) { log.debug("Create a new instance of DateTimeFormatter for format '{}' in the cache", format); return new DateTimeFormatterBuilder().appendPattern(format.getFormat()) @@ -207,7 +208,9 @@ private DateTimeFormatter createFormatter(LocaleFormatObject format) { .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) .parseDefaulting(ChronoField.DAY_OF_MONTH, 1) .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1) + // TODO: what if year changes? (e.g. the year changes as the test executes) .parseDefaulting(ChronoField.YEAR_OF_ERA, Year.now().getValue()) + // TODO: offset seconds might vary over time, so it is likely we should not provide a default for OFFSET_SECONDS .parseDefaulting(ChronoField.OFFSET_SECONDS, ZonedDateTime.now().getOffset().getTotalSeconds()) .toFormatter(format.getLocale()); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java index 9e953ef932b..49ca3d8d681 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java @@ -280,8 +280,7 @@ private HTTPSamplerProxy createSampler(Request request, String commentText) thro if (!commentText.isEmpty()) { httpSampler.setProperty(TestElement.COMMENTS,commentText); // NOSONAR } else { - httpSampler.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + httpSampler.setProperty(TestElement.COMMENTS, getDefaultComment()); } // NOSONAR URL url = new URL(request.getUrl()); httpSampler.setProtocol(url.getProtocol()); @@ -344,8 +343,7 @@ private HeaderManager createHeaderManager(Request request) { HeaderManager headerManager = new HeaderManager(); headerManager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName()); headerManager.setProperty(TestElement.NAME, "HTTP HeaderManager"); - headerManager.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + headerManager.setProperty(TestElement.COMMENTS, getDefaultComment()); Map map = request.getHeaders(); boolean hasAcceptEncoding = false; for (Map.Entry header : map.entrySet()) { @@ -368,8 +366,7 @@ private HeaderManager createHeaderManager(Request request) { private void createCookieManager(CookieManager cookieManager, Request request) { cookieManager.setProperty(TestElement.GUI_CLASS, CookiePanel.class.getName()); cookieManager.setProperty(TestElement.NAME, "HTTP CookieManager"); - cookieManager.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + cookieManager.setProperty(TestElement.COMMENTS, getDefaultComment()); if (!request.getCookies(request.getUrl()).isEmpty()) { for (Cookie c : request.getCookies(request.getUrl())) { cookieManager.getCookies().addItem(c); @@ -401,8 +398,7 @@ private KeystoreConfig createKeystoreConfiguration() { KeystoreConfig keystoreConfig = new KeystoreConfig(); keystoreConfig.setProperty(TestElement.GUI_CLASS, TestBeanGUI.class.getName()); keystoreConfig.setProperty(TestElement.NAME, "Keystore Configuration"); - keystoreConfig.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + keystoreConfig.setProperty(TestElement.COMMENTS, getDefaultComment()); return keystoreConfig; } @@ -415,8 +411,7 @@ private void createAuthManager(Request request, AuthManager authManager) { Authorization auth = request.getAuthorization(); authManager.setProperty(TestElement.GUI_CLASS, AuthPanel.class.getName()); authManager.setProperty(TestElement.NAME, "HTTP AuthorizationManager"); - authManager.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + authManager.setProperty(TestElement.COMMENTS, getDefaultComment()); authManager.getAuthObjects().addItem(auth); } @@ -460,8 +455,7 @@ private void createDnsServer(Request request, DNSCacheManager dnsCacheManager) { Set dnsServers = request.getDnsServers(); dnsCacheManager.setProperty(TestElement.GUI_CLASS, DNSCachePanel.class.getName()); dnsCacheManager.setProperty(TestElement.NAME, "DNS Cache Manager"); - dnsCacheManager.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + dnsCacheManager.setProperty(TestElement.COMMENTS, getDefaultComment()); dnsCacheManager.getServers().clear(); for (String dnsServer : dnsServers) { dnsCacheManager.addServer(dnsServer); @@ -491,12 +485,16 @@ private void createDnsResolver(Request request, DNSCacheManager dnsCacheManager) "Custom DNS resolver doesn't support port "+port); } else { - dnsCacheManager.setProperty(TestElement.COMMENTS, - "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); + dnsCacheManager.setProperty(TestElement.COMMENTS, getDefaultComment()); } dnsCacheManager.addHost(resolveParameters[0], resolveParameters[2]); } + @SuppressWarnings("JavaTimeDefaultTimeZone") + private static String getDefaultComment() { + return "Created from cURL on " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME); + } + private boolean canAddDnsResolverInHttpRequest(Request request, DNSCacheManager dnsCacheManager) { if (dnsCacheManager.getHosts().size() != 1) { return true; From ac19a29f0029bfdd0dc2723012e4281e41d3c62f Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 21:02:20 +0300 Subject: [PATCH 30/40] Inline format specifiers when they are used only once See https://errorprone.info/bugpattern/InlineFormatString --- .../apache/jmeter/report/config/ConfigurationUtils.java | 4 +--- .../org/apache/jmeter/report/core/SampleMetadata.java | 6 ++---- .../jmeter/report/dashboard/AbstractDataExporter.java | 3 +-- .../jmeter/report/dashboard/HtmlTemplateExporter.java | 3 +-- .../apache/jmeter/report/dashboard/ReportGenerator.java | 6 ++---- .../report/processor/NormalizerSampleConsumer.java | 7 +++---- .../graph/impl/ResponseTimePerSampleGraphConsumer.java | 4 +--- .../ResponseTimePercentilesOverTimeGraphConsumer.java | 4 +--- .../http/util/DirectAccessByteArrayOutputStream.java | 2 +- .../jmeter/protocol/mail/sampler/MailFileFolder.java | 9 +++++---- 10 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/report/config/ConfigurationUtils.java b/src/core/src/main/java/org/apache/jmeter/report/config/ConfigurationUtils.java index b1cdc9c8276..5e7370995f1 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/config/ConfigurationUtils.java +++ b/src/core/src/main/java/org/apache/jmeter/report/config/ConfigurationUtils.java @@ -28,8 +28,6 @@ */ public class ConfigurationUtils { - private static final String NOT_SUPPORTED_CONVERSION_FMT = "Convert \"%s\" to \"%s\" is not supported"; - /** * Instantiates a new configuration utils. */ @@ -55,7 +53,7 @@ public static TProperty convert(String value, return Converters.convert(clazz, value); } catch (ConvertException ex) { throw new ConfigurationException(String.format( - NOT_SUPPORTED_CONVERSION_FMT, value, clazz.getName())); + "Convert \"%s\" to \"%s\" is not supported", value, clazz.getName())); } } } diff --git a/src/core/src/main/java/org/apache/jmeter/report/core/SampleMetadata.java b/src/core/src/main/java/org/apache/jmeter/report/core/SampleMetadata.java index 7afe8dbe733..9fed643602d 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/core/SampleMetadata.java +++ b/src/core/src/main/java/org/apache/jmeter/report/core/SampleMetadata.java @@ -38,9 +38,6 @@ */ public class SampleMetadata { - private static final String METADATA_EXCEPTION_MSG_FMT = "No column <%s> found in sample metadata <%s>," - + " check #jmeter.save.saveservice.* properties to add the missing column"; - /** The column list : accessed by CSVSampleWriter */ List columns; @@ -216,7 +213,8 @@ public int ensureIndexOf(String col) { int index = indexOf(col); if (index < 0) { throw new SampleException( - String.format(METADATA_EXCEPTION_MSG_FMT, col, toString())); + String.format("No column <%s> found in sample metadata <%s>," + + " check #jmeter.save.saveservice.* properties to add the missing column", col, toString())); } return index; } diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/AbstractDataExporter.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/AbstractDataExporter.java index bbe1fdda992..d0f159a6a2a 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/AbstractDataExporter.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/AbstractDataExporter.java @@ -28,7 +28,6 @@ * The Class AbstractDataExporter provides a base class for DataExporter. */ public abstract class AbstractDataExporter implements DataExporter { - private static final String INVALID_PROPERTY_CONFIG_FMT = "Wrong property \"%s\" in \"%s\" export configuration"; private String name; @@ -124,7 +123,7 @@ protected T getPropertyFromConfig( try { return cfg.getProperty(property, defaultValue, clazz); } catch (ConfigurationException ex) { - throw new ExportException(String.format(INVALID_PROPERTY_CONFIG_FMT, + throw new ExportException(String.format("Wrong property \"%s\" in \"%s\" export configuration", property, getName()), ex); } } diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java index b4a9a5f1482..a886d744d24 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java @@ -80,7 +80,6 @@ public class HtmlTemplateExporter extends AbstractDataExporter { public static final String DATA_CTX_FILTERS_ONLY_SAMPLE_SERIES = "filtersOnlySampleSeries"; public static final String TIMESTAMP_FORMAT_MS = "ms"; - private static final String INVALID_TEMPLATE_DIRECTORY_FMT = "\"%s\" is not a valid template directory"; // Template directory private static final String TEMPLATE_DIR = "template_dir"; @@ -311,7 +310,7 @@ public void export(SampleContext context, File file, File.class); if (!templateDirectory.isDirectory()) { String message = String.format( - INVALID_TEMPLATE_DIRECTORY_FMT, + "\"%s\" is not a valid template directory", templateDirectory.getAbsolutePath()); log.error(message); throw new ExportException(message); diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java index 1e2625f9740..35a3779b51a 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java @@ -85,8 +85,6 @@ public class ReportGenerator { .charAt(0); private static final String INVALID_CLASS_FMT = "Class name \"%s\" is not valid."; - private static final String INVALID_EXPORT_FMT = "Data exporter \"%s\" is unable to export data."; - private static final String NOT_SUPPORTED_CONVERSION_FMT = "Not supported conversion to \"%s\""; public static final String NORMALIZER_CONSUMER_NAME = "normalizer"; public static final String BEGIN_DATE_CONSUMER_NAME = "beginDate"; @@ -382,7 +380,7 @@ private void exportData(SampleContext sampleContext, String exporterName, String error = String.format(INVALID_CLASS_FMT, className); throw new GenerationException(error, ex); } catch (ExportException ex) { - String error = String.format(INVALID_EXPORT_FMT, exporterName); + String error = String.format("Data exporter \"%s\" is unable to export data.", exporterName); throw new GenerationException(error, ex); } } @@ -534,7 +532,7 @@ private void setProperty(String className, Object obj, Method[] methods, if (converter == null) { throw new GenerationException( String.format( - NOT_SUPPORTED_CONVERSION_FMT, + "Not supported conversion to \"%s\"", parameterType.getName())); } method.invoke(obj, converter.convert(propertyValue)); diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java b/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java index 4fd85293dee..7834af8f4e5 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/NormalizerSampleConsumer.java @@ -44,9 +44,6 @@ public class NormalizerSampleConsumer extends AbstractSampleConsumer { "jmeter.save.saveservice.timestamp_format", // $NON-NLS-1$ SampleSaveConfiguration.MILLISECONDS); - private static final String PARSE_TIMESTAMP_EXCEPTION_MESSAGE = - "Could not parse timeStamp <%s> using format defined by property jmeter.save.saveservice.timestamp_format=%s on sample %s "; - /** * index of the timeStamp column */ @@ -104,7 +101,9 @@ public void consume(Sample s, int channel) { } } catch (Exception e) { throw new SampleException(String.format( - PARSE_TIMESTAMP_EXCEPTION_MESSAGE, s.getData(timestamp), + "Could not parse timeStamp <%s> using format defined by property" + + " jmeter.save.saveservice.timestamp_format=%s on sample %s ", + s.getData(timestamp), TIMESTAMP_FORMAT, s.toString()), e); } long time = date.getTime(); diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePerSampleGraphConsumer.java b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePerSampleGraphConsumer.java index 498b487113f..b16643671ba 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePerSampleGraphConsumer.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePerSampleGraphConsumer.java @@ -41,8 +41,6 @@ */ public class ResponseTimePerSampleGraphConsumer extends AbstractGraphConsumer { - private static final String RESPONSE_TIME_PER_SAMPLE_SERIES_FORMAT = "%dth percentile"; - /** * Instantiates a new response time per sample graph consumer. */ @@ -80,7 +78,7 @@ private GroupInfo createGroupInfo(String propertyKey, int defaultValue) { factory.setPercentileIndex(property); StaticSeriesSelector seriesSelector = new StaticSeriesSelector(); seriesSelector.setSeriesName(String.format( - RESPONSE_TIME_PER_SAMPLE_SERIES_FORMAT, property)); + "%dth percentile", property)); return new GroupInfo(factory, seriesSelector, // We include Transaction Controller results diff --git a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePercentilesOverTimeGraphConsumer.java b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePercentilesOverTimeGraphConsumer.java index 7c636b69d66..e0d575e7ddb 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePercentilesOverTimeGraphConsumer.java +++ b/src/core/src/main/java/org/apache/jmeter/report/processor/graph/impl/ResponseTimePercentilesOverTimeGraphConsumer.java @@ -50,8 +50,6 @@ public class ResponseTimePercentilesOverTimeGraphConsumer private static final String PCT3_LABEL = JMeterUtils.getPropDefault( "aggregate_rpt_pct3", "99"); - private static final String PERCENTILE_FORMAT = "%sth percentile"; - @Override protected TimeStampKeysSelector createTimeStampKeysSelector() { TimeStampKeysSelector keysSelector = new TimeStampKeysSelector(); @@ -77,7 +75,7 @@ protected Map createGroupInfos() { } private String formatPercentile(String percentileLabel) { - return String.format(PERCENTILE_FORMAT, percentileLabel); + return String.format("%sth percentile", percentileLabel); } private GroupInfo createMinGroupInfo() { diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/DirectAccessByteArrayOutputStream.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/DirectAccessByteArrayOutputStream.java index 376ba332b64..5f4fd604687 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/DirectAccessByteArrayOutputStream.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/DirectAccessByteArrayOutputStream.java @@ -32,8 +32,8 @@ public DirectAccessByteArrayOutputStream(int initialSize) { super(initialSize); } - @SuppressWarnings("sync-override") @Override + @SuppressWarnings({"sync-override", "UnsynchronizedOverridesSynchronized"}) public byte[] toByteArray() { // no need to copy the buffer if it has the right size // avoid an unneeded memory allocation diff --git a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java index edce502f1d5..d5721d68402 100644 --- a/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java +++ b/src/protocol/mail/src/main/java/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java @@ -23,6 +23,7 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; +import java.util.regex.Pattern; import javax.mail.Flags; import javax.mail.Folder; @@ -33,12 +34,12 @@ public class MailFileFolder extends Folder { - private static final String FILENAME_FORMAT = "%d.msg"; - private static final String FILENAME_REGEX = "\\d+\\.msg"; + private static final Pattern FILENAME_REGEX = Pattern.compile("\\d+\\.msg"); private boolean isOpen; private final File folderPath;// Parent folder (or single message file) private final boolean isFile; - private static final FilenameFilter FILENAME_FILTER = (dir, name) -> name.matches(FILENAME_REGEX); + private static final FilenameFilter FILENAME_FILTER = + (dir, name) -> FILENAME_REGEX.matcher(name).matches(); public MailFileFolder(Store store, String path) { super(store); @@ -103,7 +104,7 @@ public Message getMessage(int index) throws MessagingException { if (isFile) { f = folderPath; } else { - f = new File(folderPath,String.format(FILENAME_FORMAT, index)); + f = new File(folderPath,String.format("%d.msg", index)); } try (InputStream fis = new FileInputStream(f); InputStream bis = new BufferedInputStream(fis)) { From ecf72b7aa48238bffac1281198f63dca9af1b6fe Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 22:37:12 +0300 Subject: [PATCH 31/40] Resolve MixedMutabilityReturnType: make the returned lists unmodifiable See https://errorprone.info/bugpattern/MixedMutabilityReturnType --- .../java/org/apache/jmeter/extractor/BoundaryExtractor.java | 2 +- .../main/java/org/apache/jmeter/extractor/HtmlExtractor.java | 2 +- .../java/org/apache/jmeter/extractor/RegexExtractor.java | 2 +- .../apache/jmeter/extractor/json/jsonpath/JSONManager.java | 2 +- .../apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java | 5 +---- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/BoundaryExtractor.java b/src/components/src/main/java/org/apache/jmeter/extractor/BoundaryExtractor.java index f11334ed9d3..e10089b8787 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/BoundaryExtractor.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/BoundaryExtractor.java @@ -296,7 +296,7 @@ private List extract(String leftBoundary, String rightBoundary, int matc } } - return matches; + return Collections.unmodifiableList(matches); } public List extractAll( diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/HtmlExtractor.java b/src/components/src/main/java/org/apache/jmeter/extractor/HtmlExtractor.java index 4a59889377e..af1fe30805c 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/HtmlExtractor.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/HtmlExtractor.java @@ -188,7 +188,7 @@ private List extractMatchingStrings( } } } - return result; + return Collections.unmodifiableList(result); } /** diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java b/src/components/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java index 0863da9b37a..6513311c6b9 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java @@ -209,7 +209,7 @@ private List processMatches(Pattern pattern, String regex, SampleRe } } } - return matches; + return Collections.unmodifiableList(matches); } private int matchStrings(int matchNumber, Perl5Matcher matcher, diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java b/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java index 03a4ee5c09c..f156f3d7c8c 100644 --- a/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java +++ b/src/components/src/main/java/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java @@ -84,7 +84,7 @@ public List extractWithJsonPath(String jsonString, String jsonPath) for (Object obj: extractedObjects) { results.add(stringifyJSONObject(obj)); } - return results; + return Collections.unmodifiableList(results); } @SuppressWarnings("unchecked") diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java index c2afb32e220..d18afbf0d27 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java @@ -29,7 +29,6 @@ import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Predicate; @@ -474,9 +473,7 @@ private Map setConnectionAuthorization(HttpURLConnection conn, U conn.setRequestProperty(HTTPConstants.HEADER_AUTHORIZATION, headerValue); // Java hides request properties so we have to // keep trace of it - Map map = new HashMap<>(1); - map.put(HTTPConstants.HEADER_AUTHORIZATION, headerValue); - return map; + return Collections.singletonMap(HTTPConstants.HEADER_AUTHORIZATION, headerValue); } } return Collections.emptyMap(); From 8f5ca8d69ffc6e10dc9fe36029e17ddb97bf84ef Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 22:42:46 +0300 Subject: [PATCH 32/40] Suppress UnnecessaryAnonymousClass as the only two warnings seem to be false positives See https://errorprone.info/bugpattern/UnnecessaryAnonymousClass --- .../org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index 47c26fc0729..4e8a4f3e93b 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -431,6 +431,7 @@ public void connect(ManagedHttpClientConnection conn, HttpHost host, InetSocketA private static final Pattern PORT_PATTERN = Pattern.compile("\\d+"); // only used in .matches(), no need for anchors + @SuppressWarnings("UnnecessaryAnonymousClass") private static final ConnectionKeepAliveStrategy IDLE_STRATEGY = new DefaultConnectionKeepAliveStrategy(){ @Override public long getKeepAliveDuration(HttpResponse response, HttpContext context) { @@ -477,6 +478,7 @@ protected HttpResponse doSendRequest( * that HC core {@link ResponseContentEncoding} removes after uncompressing * See Bug 59401 */ + @SuppressWarnings("UnnecessaryAnonymousClass") private static final HttpResponseInterceptor RESPONSE_CONTENT_ENCODING = new ResponseContentEncoding(createLookupRegistry()) { @Override public void process(HttpResponse response, HttpContext context) From 8ae3458c75e357e805a775d5812ed2c400b8f9c1 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 22:45:03 +0300 Subject: [PATCH 33/40] Resolve SynchronizeOnNonFinalField --- .../apache/jmeter/visualizers/ViewResultsFullVisualizer.java | 2 +- .../src/main/java/org/apache/jmeter/threads/ThreadGroup.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java index 191716903e7..d4520d55820 100644 --- a/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java +++ b/src/components/src/main/java/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java @@ -129,7 +129,7 @@ public class ViewResultsFullVisualizer extends AbstractVisualizer private Object resultsObject = null; private TreeSelectionEvent lastSelectionEvent; private JCheckBox autoScrollCB; - private Queue buffer; + private final Queue buffer; private boolean dataChanged; /** diff --git a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java index 5414b3594b5..9cc7df29459 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java @@ -321,6 +321,7 @@ private JMeterThread makeThread( } @Override + @SuppressWarnings("SynchronizeOnNonFinalField") public JMeterThread addNewThread(int delay, StandardJMeterEngine engine) { long now = System.currentTimeMillis(); JMeterContext context = JMeterContextService.getContext(); From 9d7b694e982f09c51c5c3ab89800e24e142c1f6a Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 22:47:15 +0300 Subject: [PATCH 34/40] Suppress warnings for Hashtable usage when the class is required for Java API --- .../java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java | 2 ++ .../org/apache/jmeter/protocol/ldap/sampler/LdapClient.java | 1 + .../org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java | 1 + 3 files changed, 4 insertions(+) diff --git a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java index d10710b4609..62d74887469 100644 --- a/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java +++ b/src/protocol/jms/src/main/java/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java @@ -697,6 +697,7 @@ public void threadStarted() { } } + @SuppressWarnings("JdkObsolete") private Context getInitialContext() throws NamingException { Hashtable table = new Hashtable<>(); @@ -727,6 +728,7 @@ private Context getInitialContext() throws NamingException { return initialContext; } + @SuppressWarnings("JdkObsolete") private void printEnvironment(Context context) throws NamingException { try { Hashtable env = context.getEnvironment(); diff --git a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapClient.java b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapClient.java index c7e972f56ea..1449a89739b 100644 --- a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapClient.java +++ b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapClient.java @@ -64,6 +64,7 @@ public LdapClient() { * if {@link InitialDirContext} can not be build using the above * parameters */ + @SuppressWarnings("JdkObsolete") public void connect(String host, String port, String rootdn, String username, String password) throws NamingException { Hashtable env = new Hashtable<>(); diff --git a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java index 5584bfdce2f..a24b276e3b4 100644 --- a/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java +++ b/src/protocol/ldap/src/main/java/org/apache/jmeter/protocol/ldap/sampler/LdapExtClient.java @@ -75,6 +75,7 @@ private LdapExtClient() { * @exception NamingException * when creating the {@link DirContext} fails */ + @SuppressWarnings("JdkObsolete") public static DirContext connect(String host, String port, String rootdn, From a4c1ab897bbd2a484a330eeeaaa7b7b1f0752fa0 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 22:59:22 +0300 Subject: [PATCH 35/40] Move .lock() statements out of try to avoid accidetal release if lock fails See https://errorprone.info/bugpattern/LockNotBeforeTry --- .../src/main/java/org/apache/jmeter/threads/JMeterThread.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java b/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java index b643f8fcf29..b33c763b89a 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/JMeterThread.java @@ -321,8 +321,8 @@ public void run() { throw e; // Must not ignore this one } finally { currentSamplerForInterruption = null; // prevent any further interrupts + interruptLock.lock(); // make sure current interrupt is finished, prevent another starting yet try { - interruptLock.lock(); // make sure current interrupt is finished, prevent another starting yet threadContext.clear(); log.info("Thread finished: {}", threadName); threadFinished(iterationListener); @@ -819,8 +819,8 @@ public void stop() { // Called by StandardJMeterEngine, TestAction and AccessLog /** {@inheritDoc} */ @Override public boolean interrupt(){ + interruptLock.lock(); try { - interruptLock.lock(); Sampler samp = currentSamplerForInterruption; // fetch once; must be done under lock if (samp instanceof Interruptible){ // (also protects against null) if (log.isWarnEnabled()) { From ee0aead60c528147f51eeff784e61cbadfc22641 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 23:06:59 +0300 Subject: [PATCH 36/40] Suppress StaticAssignmentInConstructor in Summarizer --- .../src/main/java/org/apache/jmeter/reporters/Summariser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java b/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java index ee56dbb6a2d..8b4ebe2e15d 100644 --- a/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java +++ b/src/core/src/main/java/org/apache/jmeter/reporters/Summariser.java @@ -121,8 +121,9 @@ public class Summariser extends AbstractTestElement * Called several times during test startup. * The name will not necessarily have been set at this point. */ + @SuppressWarnings("StaticAssignmentInConstructor") public Summariser() { - super(); + // TODO: is it needed to reset static field instanceCount in the instance constructor? synchronized (LOCK) { ACCUMULATORS.clear(); instanceCount=0; From 7e2a47d436c26b100c40eb5b4698a651b7aa7938 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 23:08:12 +0300 Subject: [PATCH 37/40] Suppress JdkObsolete when using appendReplacement(StringBuffer,...) Unfortunately, error-prone can't detect that false positive yet --- .../java/org/apache/jmeter/report/dashboard/ReportGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java index 35a3779b51a..f66cf7b3be0 100644 --- a/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java +++ b/src/core/src/main/java/org/apache/jmeter/report/dashboard/ReportGenerator.java @@ -173,6 +173,7 @@ private static Properties loadProps(File file) { * @param propertyKey the property key * @return the name of the property setter */ + @SuppressWarnings("JdkObsolete") private static String getSetterName(String propertyKey) { Matcher matcher = POTENTIAL_CAMEL_CASE_PATTERN.matcher(propertyKey); StringBuffer buffer = new StringBuffer(); // NOSONAR Unfortunately Matcher does not support StringBuilder From 5fad27c39e9a4fbac68342dc4fd25b2a5fc8f986 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 23:08:49 +0300 Subject: [PATCH 38/40] Suppress JavaLangClash for ThreadGroup --- .../src/main/java/org/apache/jmeter/threads/ThreadGroup.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java index 9cc7df29459..bf5bd775ef1 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java @@ -41,6 +41,7 @@ * This class is intended to be ThreadSafe. */ @GUIMenuSortOrder(1) +@SuppressWarnings("JavaLangClash") public class ThreadGroup extends AbstractThreadGroup { private static final long serialVersionUID = 282L; From ebe65b86afcf706da95b2196f91afb1e74817d8c Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 23:11:21 +0300 Subject: [PATCH 39/40] Avoid NarrowingCompoundAssignment warning int += long pattern hides a lossy cast, so it is better to write that explicitly --- .../src/main/java/org/apache/jmeter/threads/ThreadGroup.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java index bf5bd775ef1..ad0e0012180 100644 --- a/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java +++ b/src/core/src/main/java/org/apache/jmeter/threads/ThreadGroup.java @@ -233,7 +233,9 @@ public void start(int groupNum, ListenerNotifier notifier, ListedHashTree thread long nowInMillis = System.currentTimeMillis(); if(threadNum > 0) { long timeElapsedToStartLastThread = nowInMillis - lastThreadStartInMillis; - delayForNextThreadInMillis += perThreadDelayInMillis - timeElapsedToStartLastThread; + // Note: `int += long` assignment hides lossy cast to int + delayForNextThreadInMillis = (int) (delayForNextThreadInMillis + + (perThreadDelayInMillis - timeElapsedToStartLastThread)); } if (log.isDebugEnabled()) { log.debug("Computed delayForNextThreadInMillis:{} for thread:{}", delayForNextThreadInMillis, Thread.currentThread().getId()); From 150a2753b4bb055c678965a1ec9a66af3362345d Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Sun, 18 Oct 2020 23:13:46 +0300 Subject: [PATCH 40/40] Make members of final classes package-private See https://errorprone.info/bugpattern/ProtectedMembersInFinalClass --- .../main/java/org/apache/jmeter/gui/action/ActionRouter.java | 4 ++-- .../java/org/apache/jmeter/gui/util/JSyntaxSearchToolBar.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/ActionRouter.java b/src/core/src/main/java/org/apache/jmeter/gui/action/ActionRouter.java index b774d96e4b8..18433ccb418 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/action/ActionRouter.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/action/ActionRouter.java @@ -280,7 +280,7 @@ public void removePostActionListener(Class action, ActionListener listener) { * @param action {@link Class} * @param e {@link ActionEvent} */ - protected void preActionPerformed(Class action, ActionEvent e) { + void preActionPerformed(Class action, ActionEvent e) { actionPerformed(action, e, preActionListeners); } @@ -288,7 +288,7 @@ protected void preActionPerformed(Class action, ActionEvent e * @param action {@link Class} * @param e {@link ActionEvent} */ - protected void postActionPerformed(Class action, ActionEvent e) { + void postActionPerformed(Class action, ActionEvent e) { actionPerformed(action, e, postActionListeners); } diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxSearchToolBar.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxSearchToolBar.java index adcc3b27e7e..4121819a5f3 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxSearchToolBar.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxSearchToolBar.java @@ -104,7 +104,7 @@ public void actionPerformed(ActionEvent evt) { } } - protected void toggleSearchField(JTextField textToFindField, boolean matchFound) { + void toggleSearchField(JTextField textToFindField, boolean matchFound) { if(!matchFound) { textToFindField.setBackground(LIGHT_RED); textToFindField.setForeground(Color.WHITE);