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