Skip to content

Commit 7b0d194

Browse files
Sean LearySean Leary
authored andcommitted
tech-debt-25250701 add jacoco to gradle build, refactor JSONObject to restore performance
1 parent 197afdd commit 7b0d194

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44
apply plugin: 'java'
55
apply plugin: 'eclipse'
6-
// apply plugin: 'jacoco'
6+
apply plugin: 'jacoco'
77
apply plugin: 'maven-publish'
88

9+
// for now, publishing to maven is still a manual process
910
//plugins {
1011
// id 'java'
1112
//id 'maven-publish'
@@ -19,6 +20,17 @@ repositories {
1920
}
2021
}
2122

23+
// To view the report open build/reports/jacoco/test/html/index.html
24+
jacocoTestReport {
25+
reports {
26+
html.required = true
27+
}
28+
}
29+
30+
test {
31+
finalizedBy jacocoTestReport
32+
}
33+
2234
dependencies {
2335
testImplementation 'junit:junit:4.13.2'
2436
testImplementation 'com.jayway.jsonpath:json-path:2.9.0'

src/main/java/org/json/JSONObject.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,30 +1780,32 @@ private void populateMap(Object bean, Set<Object> objectsRecord, JSONParserConfi
17801780

17811781
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
17821782
for (final Method method : methods) {
1783-
final String key = getKeyNameFromMethod(method);
1784-
if (key != null && !key.isEmpty()) {
1785-
try {
1786-
final Object result = method.invoke(bean);
1787-
if (result != null || jsonParserConfiguration.isUseNativeNulls()) {
1788-
// check cyclic dependency and throw error if needed
1789-
// the wrap and populateMap combination method is
1790-
// itself DFS recursive
1791-
if (objectsRecord.contains(result)) {
1792-
throw recursivelyDefinedObjectException(key);
1793-
}
1783+
if (isValidMethod(method)) {
1784+
final String key = getKeyNameFromMethod(method);
1785+
if (key != null && !key.isEmpty()) {
1786+
try {
1787+
final Object result = method.invoke(bean);
1788+
if (result != null || jsonParserConfiguration.isUseNativeNulls()) {
1789+
// check cyclic dependency and throw error if needed
1790+
// the wrap and populateMap combination method is
1791+
// itself DFS recursive
1792+
if (objectsRecord.contains(result)) {
1793+
throw recursivelyDefinedObjectException(key);
1794+
}
17941795

1795-
objectsRecord.add(result);
1796+
objectsRecord.add(result);
17961797

1797-
testValidity(result);
1798-
this.map.put(key, wrap(result, objectsRecord));
1798+
testValidity(result);
1799+
this.map.put(key, wrap(result, objectsRecord));
17991800

1800-
objectsRecord.remove(result);
1801+
objectsRecord.remove(result);
18011802

1802-
closeClosable(result);
1803+
closeClosable(result);
1804+
}
1805+
} catch (IllegalAccessException ignore) {
1806+
} catch (IllegalArgumentException ignore) {
1807+
} catch (InvocationTargetException ignore) {
18031808
}
1804-
} catch (IllegalAccessException ignore) {
1805-
} catch (IllegalArgumentException ignore) {
1806-
} catch (InvocationTargetException ignore) {
18071809
}
18081810
}
18091811
}
@@ -1814,10 +1816,6 @@ private static boolean isValidMethodName(String name) {
18141816
}
18151817

18161818
private static String getKeyNameFromMethod(Method method) {
1817-
if (!isValidMethod(method)) {
1818-
return null;
1819-
}
1820-
18211819
final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class);
18221820
if (ignoreDepth > 0) {
18231821
final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class);

0 commit comments

Comments
 (0)