You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2019/07/23 06:51:24 UTC
[jmeter] branch master updated: Fix Sonar reported bugs
This is an automated email from the ASF dual-hosted git repository.
pmouawad pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new 95f3419 Fix Sonar reported bugs
95f3419 is described below
commit 95f341901e7a2e422b12661079516002f69d9ed2
Author: pmouawad <p....@ubik-ingenierie.com>
AuthorDate: Tue Jul 23 08:51:09 2019 +0200
Fix Sonar reported bugs
---
.../jmeter/protocol/http/curl/BasicCurlParser.java | 27 ++++++++++------------
.../http/gui/action/ParseCurlCommandAction.java | 25 +++++++++++---------
.../protocol/ldap/sampler/LDAPExtSampler.java | 2 +-
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java b/src/protocol/http/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
index 6471848..a59a98c 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
@@ -882,10 +882,11 @@ public class BasicCurlParser {
* Set the parameters of proxy server in http request advanced
*
* @param request http request
- * @param proxyServerParameters the parameters of proxy server
+ * @param originalProxyServerParameters the parameters of proxy server
*
*/
- private void setProxyServer(Request request, String proxyServerParameters) {
+ private void setProxyServer(Request request, String originalProxyServerParameters) {
+ String proxyServerParameters = originalProxyServerParameters;
if (!proxyServerParameters.contains("://")) {
proxyServerParameters = "http://" + proxyServerParameters;
}
@@ -907,8 +908,7 @@ public class BasicCurlParser {
request.setProxyServer("port", "1080");
}
} catch (URISyntaxException e) {
- LOGGER.error("string '{}' cannot be converted to a URL", proxyServerParameters);
- throw new IllegalArgumentException(proxyServerParameters + " cannot be converted to a URL");
+ throw new IllegalArgumentException(proxyServerParameters + " cannot be converted to a URL", e);
}
}
@@ -929,11 +929,12 @@ public class BasicCurlParser {
/**
* Get post data by different type of data option
*
- * @param postdata the post data
+ * @param originalPostdata the post data
* @param dataOptionName the different option of "--data"
* @return the post data
*/
- private String getPostDataByDifferentOption(String postdata, String dataOptionName) {
+ private String getPostDataByDifferentOption(final String originalPostdata, String dataOptionName) {
+ String postdata = originalPostdata;
if ("data-urlencode".equals(dataOptionName)) {
postdata = encodePostdata(postdata);
} else {
@@ -963,7 +964,7 @@ public class BasicCurlParser {
try {
contentFile = URLEncoder.encode(dataToEncode, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
- LOGGER.error("string '{}' cannot be encoded", dataToEncode);// NOSONAR
+ throw new IllegalArgumentException(dataToEncode + " cannot be encoded", e);
}
if (!arr[0].isEmpty()) {
contentFile = arr[0] + "=" + contentFile;
@@ -974,8 +975,7 @@ public class BasicCurlParser {
try {
return URLEncoder.encode(postdata, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
- LOGGER.error("string '{}' cannot be encoded", postdata);
- throw new IllegalArgumentException(postdata + " cannot be encoded");
+ throw new IllegalArgumentException(postdata + " cannot be encoded", e);
}
} else {
int index = postdata.indexOf('=');
@@ -983,9 +983,8 @@ public class BasicCurlParser {
return postdata.substring(0, index + 1) + URLEncoder
.encode(postdata.substring(index + 1, postdata.length()), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
- LOGGER.error("string '{}' cannot be encoded", postdata.substring(index + 1, postdata.length()));
throw new IllegalArgumentException(
- postdata.substring(index + 1, postdata.length()) + " cannot be encoded");
+ postdata.substring(index + 1, postdata.length()) + " cannot be encoded", e);
}
}
}
@@ -998,19 +997,17 @@ public class BasicCurlParser {
* @return the content of file
*/
private static String readFromFile(String filePath) {
- String content = "";
File file = new File(filePath.trim());
if (file.isFile() && file.exists()) {
try {
- content = FileUtils.readFileToString(file, StandardCharsets.UTF_8.name());
+ return FileUtils.readFileToString(file, StandardCharsets.UTF_8.name());
} catch (IOException e) {
- LOGGER.error("Failed to read from File {}", filePath);
+ LOGGER.error("Failed to read from File {}", filePath, e);
throw new IllegalArgumentException("Failed to read from File " + filePath);
}
} else {
throw new IllegalArgumentException(filePath + " is a directory or does not exist");
}
- return content;
}
/**
diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java b/src/protocol/http/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java
index 220a297..b8a3489 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/gui/action/ParseCurlCommandAction.java
@@ -114,6 +114,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
public static final String IMPORT_CURL = "import_curl";
private static final String CREATE_REQUEST = "CREATE_REQUEST";
private static final String TYPE_FORM = ";type=";
+ private static final String CERT = "cert";
/** A panel allowing results to be saved. */
private FilePanel filePanel = null;
static {
@@ -177,11 +178,10 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
private DNSCacheManager findNodeOfTypeDnsCacheManagerByType(boolean isCustom) {
JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
- DNSCacheManager dnsCacheManager=new DNSCacheManager();
List<JMeterTreeNode> res = treeModel.getNodesOfType(DNSCacheManager.class);
for (JMeterTreeNode jm : res) {
- dnsCacheManager = (DNSCacheManager) jm.getTestElement();
- if (dnsCacheManager.isCustomResolver()==isCustom) {
+ DNSCacheManager dnsCacheManager = (DNSCacheManager) jm.getTestElement();
+ if (dnsCacheManager.isCustomResolver() == isCustom) {
return dnsCacheManager;
}
}
@@ -253,7 +253,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
HTTPSamplerProxy httpSampler = createSampler(request,commentText);
HashTree samplerHT = parentHT.add(httpSampler);
samplerHT.add(httpSampler.getHeaderManager());
- if (request.getCaCert().equals("cert")) {
+ if (CERT.equals(request.getCaCert())) {
samplerHT.add(httpSampler.getKeystoreConfig());
}
return httpSampler;
@@ -299,7 +299,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
setFormData(request, httpSampler);
httpSampler.setDoMultipart(true);
}
- if (request.getCaCert().equals("cert")) {
+ if (CERT.equals(request.getCaCert())) {
KeystoreConfig keystoreConfig = createKeystoreConfiguration();
httpSampler.addTestElement(keystoreConfig);
}
@@ -372,7 +372,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
try {
cookieManager.addFile(pathfileCookie);
} catch (IOException e) {
- LOGGER.error("Failed to read from File {}", pathfileCookie);
+ LOGGER.error("Failed to read from File {}", pathfileCookie, e);
throw new IllegalArgumentException("Failed to read from File " + pathfileCookie);
}
} else {
@@ -487,7 +487,9 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
dnsCacheManager.getHosts().clear();
String[]resolveParameters=request.getDnsResolver().split(":");
String port=resolveParameters[1];
- if(!port.equals("443")&&!port.equals("80")&&!port.equals("*")) {
+ if (!"443".equals(port)
+ && !"80".equals(port)
+ && !"*".equals(port)) {
dnsCacheManager.setProperty(TestElement.COMMENTS,
"Custom DNS resolver doesn't support port "+port);
}
@@ -531,11 +533,11 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
for (Map.Entry<String, String> entry : request.getFormData().entrySet()) {
String formName = entry.getKey();
String formValue = entry.getValue();
- String contentType = "";
- boolean isContainsFile = formValue.substring(0, 1).equals("@");
+ boolean isContainsFile = "@".equals(formValue.substring(0, 1));
boolean isContainsContentType = formValue.toLowerCase().contains(TYPE_FORM);
if (isContainsFile) {
formValue = formValue.substring(1, formValue.length());
+ String contentType;
if (isContainsContentType) {
String[] formValueWithType = formValue.split(TYPE_FORM);
formValue = formValueWithType[0];
@@ -548,7 +550,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
if (isContainsContentType) {
String[] formValueWithType = formValue.split(TYPE_FORM);
formValue = formValueWithType[0];
- contentType = formValueWithType[1];
+ String contentType = formValueWithType[1];
httpSampler.addNonEncodedArgument(formName, formValue, "", contentType);
} else {
httpSampler.addNonEncodedArgument(formName, formValue, "");
@@ -657,6 +659,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
}
}
} catch (Exception ex) {
+ LOGGER.error("Error creating test plan from cURL command list:{}", commandsList, ex);
statusText.setText(
MessageFormat.format(JMeterUtils.getResString("curl_create_failure"), ex.getMessage()));
statusText.setForeground(Color.RED);
@@ -749,7 +752,7 @@ public class ParseCurlCommandAction extends AbstractAction implements MenuCreato
KeystoreConfig keystoreConfig = sampler.getKeystoreConfig();
final JMeterTreeNode newNode = treeModel.addComponent(sampler, currentNode);
treeModel.addComponent(headerManager, newNode);
- if (request.getCaCert().equals("cert")) {
+ if (CERT.equals(request.getCaCert())) {
treeModel.addComponent(keystoreConfig, newNode);
}
if (canAddAuthManagerInHttpRequest) {
diff --git a/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java b/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
index e1646bd..3543ee8 100644
--- a/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
+++ b/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPExtSampler.java
@@ -859,7 +859,7 @@ public class LDAPExtSampler extends AbstractSampler implements TestStateListener
res.setResponseCode("800"); // $NON-NLS-1$
}
isSuccessful = false;
- } catch (Exception ex) {
+ } catch (Exception ex) { // NOSONAR Exception is reported
String returnData = ex.toString();
res.setResponseCode("500");
res.setResponseMessage(returnData); // $NON-NLS-1$