Skip to content

Commit f497d51

Browse files
[refactor] Fix bugs and issues that SonarCloud reported
1 parent d7c2c38 commit f497d51

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public class XQueryContext implements BinaryValueManager, Context {
205205
private XMLGregorianCalendar calendar = null;
206206
private TimeZone implicitTimeZone = null;
207207

208-
private final Map<String, Sequence> cachedUriCollectionResults = new HashMap<String, Sequence>();
208+
private final Map<String, Sequence> cachedUriCollectionResults = new HashMap<>();
209209

210210
/**
211211
* the watchdog object assigned to this query.

exist-core/src/main/java/org/exist/xquery/functions/fn/FunUriCollection.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
9393
throw new XPathException(this, ErrorCodes.FODC0002, "No URI is supplied and default resource collection is absent.");
9494
}
9595
} else {
96-
final List<String> resultUris = new LinkedList<String>();
96+
final List<String> resultUris = new LinkedList<>();
9797

9898
final String uriWithQueryString = args[0].toString();
9999
final int queryStringIndex = uriWithQueryString.indexOf('?');
@@ -174,19 +174,21 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
174174

175175
private static Map<String, String> parseQueryString(final String uri) {
176176
final Map<String, String> map = new HashMap<>();
177-
final int questionMarkIndex = (uri == null) ? -1 : uri.indexOf('?');
178-
if (questionMarkIndex >= 0 && questionMarkIndex + 1 < uri.length()) {
179-
String[] keyValuePairs = uri.substring(questionMarkIndex + 1).split("&");
180-
for (String keyValuePair : keyValuePairs) {
181-
int equalIndex = keyValuePair.indexOf('=');
182-
if (equalIndex >= 0) {
183-
if (equalIndex + 1 < uri.length()) {
184-
map.put(keyValuePair.substring(0, equalIndex).trim(), keyValuePair.substring(equalIndex + 1).trim());
177+
if (uri != null) {
178+
final int questionMarkIndex = uri.indexOf('?');
179+
if (questionMarkIndex >= 0 && questionMarkIndex + 1 < uri.length()) {
180+
String[] keyValuePairs = uri.substring(questionMarkIndex + 1).split("&");
181+
for (String keyValuePair : keyValuePairs) {
182+
int equalIndex = keyValuePair.indexOf('=');
183+
if (equalIndex >= 0) {
184+
if (equalIndex + 1 < uri.length()) {
185+
map.put(keyValuePair.substring(0, equalIndex).trim(), keyValuePair.substring(equalIndex + 1).trim());
186+
} else {
187+
map.put(keyValuePair.substring(0, equalIndex).trim(), "");
188+
}
185189
} else {
186-
map.put(keyValuePair.substring(0, equalIndex).trim(), "");
190+
map.put(keyValuePair.trim(), "");
187191
}
188-
} else {
189-
map.put(keyValuePair.trim(), "");
190192
}
191193
}
192194
}
@@ -199,11 +201,11 @@ private void checkQueryStringMap(final Map<String, String> queryStringMap) throw
199201
final String key = queryStringEntry.getKey();
200202
final String value = queryStringEntry.getValue();
201203
if (key.equals(KEY_CONTENT_TYPE)) {
202-
if (!Arrays.stream(VALUE_CONTENT_TYPES).anyMatch(contentTypeValue -> contentTypeValue.equals(value))) {
204+
if (Arrays.stream(VALUE_CONTENT_TYPES).noneMatch(contentTypeValue -> contentTypeValue.equals(value))) {
203205
throw new XPathException(this, ErrorCodes.FODC0004, String.format("Invalid query-string value \"%s\".", queryStringEntry));
204206
}
205207
} else if (key.equals(KEY_STABLE)) {
206-
if (!Arrays.stream(VALUE_STABLES).anyMatch(stableValue -> stableValue.equals(value))) {
208+
if (Arrays.stream(VALUE_STABLES).noneMatch(stableValue -> stableValue.equals(value))) {
207209
throw new XPathException(this, ErrorCodes.FODC0004, String.format("Invalid query-string value \"%s\".", queryStringEntry));
208210
}
209211
} else if (!key.equals(KEY_MATCH)) {

0 commit comments

Comments
 (0)