Skip to content

Commit 95112dd

Browse files
Fixed code based on sonar review comments
1 parent f0b31e4 commit 95112dd

20 files changed

Lines changed: 73 additions & 63 deletions

src/main/java/com/paypal/core/AbstractCertificateHttpHeaderAuthStrategy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Map;
55

66
import com.paypal.core.credential.CertificateCredential;
7-
import com.paypal.core.credential.ICredential;
87
import com.paypal.core.credential.TokenAuthorization;
98
import com.paypal.sdk.exceptions.OAuthException;
109

src/main/java/com/paypal/core/AbstractSignatureHttpHeaderAuthStrategy.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
6-
import com.paypal.core.credential.CertificateCredential;
7-
import com.paypal.core.credential.ICredential;
85
import com.paypal.core.credential.SignatureCredential;
96
import com.paypal.core.credential.TokenAuthorization;
107
import com.paypal.sdk.exceptions.OAuthException;

src/main/java/com/paypal/core/ConfigManager.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public final class ConfigManager {
5858
DEFAULT_PROPERTIES.put(Constants.HTTP_CONNECTION_MAX_CONNECTION, "100");
5959
DEFAULT_PROPERTIES.put(Constants.DEVICE_IP_ADDRESS, "127.0.0.1");
6060
DEFAULT_PROPERTIES.put(Constants.GOOGLE_APP_ENGINE, "false");
61+
defaultMapView = new HashMap<String, String>();
62+
for (Object object : DEFAULT_PROPERTIES.keySet()) {
63+
defaultMapView.put(
64+
object.toString().trim(),
65+
DEFAULT_PROPERTIES.getProperty(
66+
object.toString()).trim());
67+
}
6168
}
6269

6370
/**
@@ -105,19 +112,6 @@ public static Properties getDefaultProperties() {
105112
* @return {@link Map} view of Default {@link Properties}
106113
*/
107114
public static Map<String, String> getDefaultSDKMap() {
108-
if (defaultMapView == null) {
109-
synchronized (DEFAULT_PROPERTIES) {
110-
if (defaultMapView == null) {
111-
defaultMapView = new HashMap<String, String>();
112-
for (Object object : DEFAULT_PROPERTIES.keySet()) {
113-
defaultMapView.put(
114-
object.toString().trim(),
115-
DEFAULT_PROPERTIES.getProperty(
116-
object.toString()).trim());
117-
}
118-
}
119-
}
120-
}
121115
return new HashMap<String, String>(defaultMapView);
122116
}
123117

src/main/java/com/paypal/core/Constants.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.paypal.core;
22

3-
public class Constants {
3+
public final class Constants {
4+
5+
private Constants() {}
46

57
// General Constants
6-
public static final String ENCODING_FORMAT = "UTF8";
8+
public static final String ENCODING_FORMAT = "UTF-8";
79
public static final String EMPTY_STRING = "";
810
public static final String ACCOUNT_PREFIX = "acct";
911

@@ -186,8 +188,5 @@ public class Constants {
186188

187189
// Client Secret
188190
public static final String CLIENT_SECRET = "clientSecret";
189-
190-
// UTF-8 encoding String
191-
public static final String UTF_8 = "UTF-8";
192191

193192
}

src/main/java/com/paypal/core/HttpConnection.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.io.BufferedReader;
44
import java.io.IOException;
55
import java.io.InputStreamReader;
6+
import java.io.OutputStream;
67
import java.io.OutputStreamWriter;
78
import java.net.HttpURLConnection;
8-
import java.net.MalformedURLException;
99
import java.nio.charset.Charset;
1010
import java.util.Iterator;
1111
import java.util.Map;
@@ -56,7 +56,8 @@ public String execute(String url, String payload,
5656
ClientActionRequiredException {
5757

5858
String successResponse = Constants.EMPTY_STRING, errorResponse = Constants.EMPTY_STRING;
59-
InputStreamReader iSR = null;
59+
InputStreamReader isr = null;
60+
OutputStream os = null;
6061
BufferedReader reader = null;
6162
OutputStreamWriter writer = null;
6263
connection.setRequestProperty("Content-Length", ""
@@ -70,16 +71,16 @@ public String execute(String url, String payload,
7071
do {
7172
try {
7273
if ("POST".equalsIgnoreCase(connection.getRequestMethod())) {
73-
writer = new OutputStreamWriter(
74-
this.connection.getOutputStream(),
74+
os = this.connection.getOutputStream();
75+
writer = new OutputStreamWriter(os,
7576
Charset.forName(Constants.ENCODING_FORMAT));
7677
writer.write(payload);
7778
writer.flush();
7879
}
7980
int responsecode = connection.getResponseCode();
80-
iSR = new InputStreamReader(connection.getInputStream(),
81+
isr = new InputStreamReader(connection.getInputStream(),
8182
Constants.ENCODING_FORMAT);
82-
reader = new BufferedReader(iSR);
83+
reader = new BufferedReader(isr);
8384
if (responsecode >= 200 && responsecode < 300) {
8485
successResponse = read(reader);
8586
LoggingManager.debug(HttpConnection.class,
@@ -136,13 +137,17 @@ public String execute(String url, String payload,
136137
if (writer != null) {
137138
writer.close();
138139
}
139-
if (iSR != null) {
140-
iSR.close();
140+
if (isr != null) {
141+
isr.close();
142+
}
143+
if (os != null) {
144+
os.close();
141145
}
142146
} finally {
143147
reader = null;
144148
writer = null;
145-
iSR = null;
149+
isr = null;
150+
os = null;
146151
}
147152
}
148153
return successResponse;

src/main/java/com/paypal/core/LoggingManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*
1111
*/
1212
public final class LoggingManager {
13+
14+
private LoggingManager() {}
15+
1316
private static Map<Class<?>, Logger> loggerMap = new HashMap<Class<?>, Logger>();
1417

1518
private static Logger getLogger(Class<?> thisClass) {

src/main/java/com/paypal/core/NVPUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9-
public class NVPUtil {
9+
public final class NVPUtil {
10+
11+
private NVPUtil() {}
1012

1113
/**
1214
* Utility method used to decode the nvp response String

src/main/java/com/paypal/core/ReflectionUtil.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import java.lang.reflect.Method;
66
import java.util.HashMap;
77
import java.util.List;
8+
import java.util.Locale;
89
import java.util.Map;
910
import java.util.Map.Entry;
1011

11-
public class ReflectionUtil {
12+
public final class ReflectionUtil {
13+
14+
private ReflectionUtil() {}
1215

1316
public static Map<String, String> decodeResponseObject(Object responseType,
1417
String prefix) {
@@ -49,11 +52,11 @@ public static Map<String, Object> generateMapFromResponse(
4952
try {
5053
if (prefix != null && prefix.length() != 0) {
5154
propertyName = prefix + "."
52-
+ m.getName().substring(3, 4).toLowerCase()
55+
+ m.getName().substring(3, 4).toLowerCase(Locale.US)
5356
+ m.getName().substring(4);
5457
} else {
5558
propertyName = m.getName().substring(3, 4)
56-
.toLowerCase()
59+
.toLowerCase(Locale.US)
5760
+ m.getName().substring(4);
5861

5962
}

src/main/java/com/paypal/core/SDKUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.paypal.core;
22

3-
import java.io.IOException;
43
import java.util.Enumeration;
54
import java.util.HashMap;
65
import java.util.Map;
@@ -11,7 +10,9 @@
1110
* SDKUtil class holds utility methods for processing data transformation
1211
*
1312
*/
14-
public class SDKUtil {
13+
public final class SDKUtil {
14+
15+
private SDKUtil() {}
1516

1617
/**
1718
* Pattern for replacing Ampersand '&' character

src/main/java/com/paypal/core/SSLUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.paypal.core;
22

33
import java.io.FileInputStream;
4-
import java.io.FileNotFoundException;
54
import java.io.IOException;
65
import java.security.KeyStore;
76
import java.security.KeyStoreException;

0 commit comments

Comments
 (0)