Skip to content

Commit 348c912

Browse files
authored
Merge pull request #1629 from kazuki43zoo/fix-some-sonar-report
Fix some sonar reports
2 parents dc8e15a + e05935d commit 348c912

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

src/main/java/org/apache/ibatis/cache/CacheKey.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ public class CacheKey implements Cloneable, Serializable {
2929

3030
private static final long serialVersionUID = 1146682552656046210L;
3131

32-
public static final CacheKey NULL_CACHE_KEY = new NullCacheKey();
32+
public static final CacheKey NULL_CACHE_KEY = new CacheKey(){
33+
@Override
34+
public void update(Object object) {
35+
throw new CacheException("Not allowed to update a null cache key instance.");
36+
}
37+
@Override
38+
public void updateAll(Object[] objects) {
39+
throw new CacheException("Not allowed to update a null cache key instance.");
40+
}
41+
};
3342

3443
private static final int DEFAULT_MULTIPLYER = 37;
3544
private static final int DEFAULT_HASHCODE = 17;

src/main/java/org/apache/ibatis/cache/NullCacheKey.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,9 @@
1717

1818
/**
1919
* @author Clinton Begin
20+
* @deprecated Since 3.5.3, This class never used and will be removed future version.
2021
*/
22+
@Deprecated
2123
public final class NullCacheKey extends CacheKey {
2224

2325
private static final long serialVersionUID = 3704229911977019465L;

src/main/java/org/apache/ibatis/io/DefaultVFS.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ public List<String> list(URL url, String path) throws IOException {
9595
* then we assume the current resource is not a directory.
9696
*/
9797
is = url.openStream();
98-
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
9998
List<String> lines = new ArrayList<>();
100-
for (String line; (line = reader.readLine()) != null;) {
101-
if (log.isDebugEnabled()) {
102-
log.debug("Reader entry: " + line);
103-
}
104-
lines.add(line);
105-
if (getResources(path + "/" + line).isEmpty()) {
106-
lines.clear();
107-
break;
99+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
100+
for (String line; (line = reader.readLine()) != null;) {
101+
if (log.isDebugEnabled()) {
102+
log.debug("Reader entry: " + line);
103+
}
104+
lines.add(line);
105+
if (getResources(path + "/" + line).isEmpty()) {
106+
lines.clear();
107+
break;
108+
}
108109
}
109110
}
110-
111111
if (!lines.isEmpty()) {
112112
if (log.isDebugEnabled()) {
113113
log.debug("Listing " + url);
@@ -223,15 +223,17 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
223223
}
224224

225225
// If the file part of the URL is itself a URL, then that URL probably points to the JAR
226-
try {
227-
for (;;) {
226+
boolean continueLoop = true;
227+
while (continueLoop) {
228+
try {
228229
url = new URL(url.getFile());
229230
if (log.isDebugEnabled()) {
230231
log.debug("Inner URL: " + url);
231232
}
233+
} catch (MalformedURLException e) {
234+
// This will happen at some point and serves as a break in the loop
235+
continueLoop = false;
232236
}
233-
} catch (MalformedURLException e) {
234-
// This will happen at some point and serves as a break in the loop
235237
}
236238

237239
// Look for the .jar extension and chop off everything after that

src/main/java/org/apache/ibatis/parsing/XPathParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.Properties;
2424

25+
import javax.xml.XMLConstants;
2526
import javax.xml.namespace.QName;
2627
import javax.xml.parsers.DocumentBuilder;
2728
import javax.xml.parsers.DocumentBuilderFactory;
@@ -230,6 +231,7 @@ private Document createDocument(InputSource inputSource) {
230231
// important: this must only be called AFTER common constructor
231232
try {
232233
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
234+
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
233235
factory.setValidating(validation);
234236

235237
factory.setNamespaceAware(false);
@@ -253,6 +255,7 @@ public void fatalError(SAXParseException exception) throws SAXException {
253255

254256
@Override
255257
public void warning(SAXParseException exception) throws SAXException {
258+
// NOP
256259
}
257260
});
258261
return builder.parse(inputSource);

0 commit comments

Comments
 (0)