Skip to content

Commit 0779dcd

Browse files
Sonarqube fixes
1 parent de9384d commit 0779dcd

File tree

8 files changed

+22
-31
lines changed

8 files changed

+22
-31
lines changed

elementfactory/src/main/java/io/github/xmljim/json/elementfactory/AbstractJsonElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ abstract class AbstractJsonElement {
77
private final NodeType type;
88
private final JsonElement parent;
99

10-
public AbstractJsonElement(NodeType type, JsonElement parent) {
10+
protected AbstractJsonElement(NodeType type, JsonElement parent) {
1111
this.type = type;
1212
this.parent = parent;
1313
}

elementfactory/src/main/java/io/github/xmljim/json/elementfactory/AbstractJsonValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public int hashCode() {
4040
@Override
4141
@SuppressWarnings("unchecked")
4242
public boolean isEquivalent(JsonElement other) {
43-
if (other instanceof JsonValue<?> value) {
44-
return compareTo((JsonValue<T>) value) == 0;
43+
if (other instanceof JsonValue<?> val) {
44+
return compareTo((JsonValue<T>) val) == 0;
4545
}
4646

4747
return false;

elementfactory/src/main/java/io/github/xmljim/json/elementfactory/NumberValue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public NumberValue(JsonElement parent, Number value) {
1212

1313
}
1414

15+
@Override
1516
public Number get() {
1617
return switch (type()) {
1718
case INTEGER -> super.get().intValue();

jsonfactory/src/main/java/io/github/xmljim/json/service/Version.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public Version(String versionString) {
4848

4949
if (matcher.matches()) {
5050

51-
int major = Integer.parseInt(matcher.group(VersionPatterns.MAJOR));
52-
int minor = matcher.group(VersionPatterns.MINOR) != null ? Integer.parseInt(matcher.group(VersionPatterns.MINOR)) : 0;
53-
int patch = matcher.group(VersionPatterns.PATCH) != null ? Integer.parseInt(matcher.group(VersionPatterns.PATCH)) : 0;
51+
int maj = Integer.parseInt(matcher.group(VersionPatterns.MAJOR));
52+
int min = matcher.group(VersionPatterns.MINOR) != null ? Integer.parseInt(matcher.group(VersionPatterns.MINOR)) : 0;
53+
int pat = matcher.group(VersionPatterns.PATCH) != null ? Integer.parseInt(matcher.group(VersionPatterns.PATCH)) : 0;
5454

55-
setMajor(major);
56-
setMinor(minor);
57-
setPatch(patch);
55+
setMajor(maj);
56+
setMinor(min);
57+
setPatch(pat);
5858
setPreRelease(matcher.group(VersionPatterns.PRERELEASE));
5959
setBuildMetadata(matcher.group(VersionPatterns.BUILDMETADATA));
6060
} else {
@@ -290,8 +290,7 @@ public Version nextPatch() {
290290
@Override
291291
public String toString() {
292292

293-
//noinspection StringBufferReplaceableByString,StringBufferMayBeStringBuilder
294-
StringBuffer builder = new StringBuffer();
293+
StringBuilder builder = new StringBuilder();
295294

296295
builder.append(getMajor()).append(".")
297296
.append(getMinor()).append(".")

jsonpath/src/main/java/io/github/xmljim/json/jsonpath/context/Context.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ public void setVariable(String key, Context context) {
125125
root.variables.put(key, context);
126126
}
127127

128-
public void getVariable(String key) {
129-
root.variables.get(key);
128+
public Context getVariable(String key) {
129+
return root.variables.get(key);
130130
}
131131

132132
@Override
133133
public boolean equals(Object other) {
134134
if (other instanceof Context o) {
135-
// System.out.printf("equals: %1$d <=> %2$d", get().hashCode(), o.get().hashCode());
136-
// System.out.println();
137135
return Objects.equals(get(), o.get());
138136
} else {
139137
return false;

jsonpath/src/main/java/io/github/xmljim/json/jsonpath/function/FunctionFactory.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
package io.github.xmljim.json.jsonpath.function;
22

3-
import io.github.xmljim.json.jsonpath.function.info.FunctionInfo;
43
import io.github.xmljim.json.jsonpath.JsonPathException;
54
import io.github.xmljim.json.jsonpath.compiler.JsonPathExpressionException;
5+
import io.github.xmljim.json.jsonpath.function.info.FunctionInfo;
66
import io.github.xmljim.json.jsonpath.util.Global;
77

88
import java.lang.reflect.Constructor;
99
import java.lang.reflect.InvocationTargetException;
10-
import java.util.ArrayDeque;
11-
import java.util.ArrayList;
12-
import java.util.Arrays;
13-
import java.util.Collections;
14-
import java.util.Deque;
15-
import java.util.List;
10+
import java.util.*;
1611
import java.util.regex.Matcher;
1712
import java.util.regex.Pattern;
1813

@@ -29,8 +24,8 @@ public static JsonPathFunction createFunction(String expression, Global global)
2924
String fxName = matcher.group("function");
3025

3126
FunctionInfo functionInfo = global.getFunctionRegistry()
32-
.getFunctionInfo(fxName)
33-
.orElseThrow(() -> new JsonPathException("Function not found: " + fxName));
27+
.getFunctionInfo(fxName)
28+
.orElseThrow(() -> new JsonPathException("Function not found: " + fxName));
3429

3530
String argsString = matcher.group("args");
3631

@@ -55,8 +50,8 @@ public static JsonPathFunction createFunction(String expression, Global global)
5550
while (matcher.find()) {
5651
if (matcher.group() != null && !"".equals(matcher.group())) {
5752
argExpressions.add(matcher.group().strip().endsWith(",") ?
58-
matcher.group().strip().substring(0, matcher.group().strip().length() - 1) :
59-
matcher.group().strip());
53+
matcher.group().strip().substring(0, matcher.group().strip().length() - 1) :
54+
matcher.group().strip());
6055
}
6156
}
6257
if (functionInfo.arguments().length != 0) {
@@ -108,9 +103,7 @@ private static JsonPathFunction newInstance(Class<? extends JsonPathFunction> fu
108103
}
109104
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
110105
IllegalAccessException e) {
111-
e.printStackTrace();
106+
throw new JsonPathException(e);
112107
}
113-
114-
return null;
115108
}
116109
}

mapper/src/main/java/io/github/xmljim/json/mapper/MemberHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void setMemberValue(JsonValue<?> value) {
8383
method.ifPresent(method1 -> setMethodValue(method1, value));
8484
}
8585
} catch (NoSuchFieldException e) {
86-
e.printStackTrace();
86+
throw new JsonMapperException(e);
8787
}
8888
}
8989

parser/src/main/java/io/github/xmljim/json/parser/util/ResizableByteBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static ResizableByteBuffer fromStream(InputStream inputStream, int alloca
9696
}
9797
} catch (final IOException e) {
9898
// TODO Auto-generated catch block
99-
e.printStackTrace();
99+
throw new JsonParserException(e);
100100
}
101101

102102
return buffer;

0 commit comments

Comments
 (0)