Skip to content

Commit

Permalink
remove custom implementation and use org.apache.commons.lang.math.Num…
Browse files Browse the repository at this point in the history
…berUtils.isNumber
  • Loading branch information
Dušan Markovič committed Mar 3, 2020
1 parent 0488f0e commit cf76b7d
Showing 1 changed file with 3 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.commons.lang.math.NumberUtils.isNumber;

public class ElasticSearchMetric {
private static final Logger logger = LoggerFactory.getLogger(ElasticSearchMetric.class);
private SampleResult sampleResult;
Expand Down Expand Up @@ -162,7 +164,7 @@ private void addCustomFields(BackendListenerContext context) {

if (!parameterName.startsWith("es.") && context.containsParameter(parameterName)
&& !"".equals(parameter = context.getParameter(parameterName).trim())) {
if (isInteger(parameter)) {
if (isNumber(parameter)) {
addFilteredJSON(parameterName, Long.parseLong(parameter));
} else {
addFilteredJSON(parameterName, parameter);
Expand Down Expand Up @@ -280,27 +282,4 @@ public Date getElapsedTime(boolean forBuildComparison) {
}
}

private static boolean isInteger(String str) {
if (str == null) {
return false;
}
int length = str.length();
if (length == 0) {
return false;
}
int i = 0;
if (str.charAt(0) == '-') {
if (length == 1) {
return false;
}
i = 1;
}
for (; i < length; i++) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
}

2 comments on commit cf76b7d

@joychester
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "import static org.apache.commons.lang.math.NumberUtils.isNumber;" in line 23 will cause the "java.lang.NoClassDefFoundError: org/apache/commons/lang/math/NumberUtils" exception, since Jmeter(v5.2.1) is using commons-lang3-3.9.jar instead of commons-lang-xxx.jar,

@anthonygauthier
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "import static org.apache.commons.lang.math.NumberUtils.isNumber;" in line 23 will cause the "java.lang.NoClassDefFoundError: org/apache/commons/lang/math/NumberUtils" exception, since Jmeter(v5.2.1) is using commons-lang3-3.9.jar instead of commons-lang-xxx.jar,

I have fixed this in version 2.6.11 (currently in SNAPSHOT). Using isCreatable instead of the deprecated isNumber method.

Please sign in to comment.