Skip to content

Commit 06d73f5

Browse files
committed
tidy
1 parent 0f631b6 commit 06d73f5

File tree

6 files changed

+50
-17
lines changed

6 files changed

+50
-17
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ JsonValue backToJson = Json.fromUntyped(Map.of(
4646
"age", user.age(),
4747
"active", user.active()
4848
));
49+
50+
// Covert back to a JSON string
51+
String jsonString = backToJson.toString();
4952
```
5053

5154
## Backport Project Goals
@@ -74,8 +77,8 @@ The original proposal and design rationale can be found in the included PDF: [To
7477
## Modifications
7578

7679
This is a simplified backport with the following changes from the original:
77-
- Replaced StableValue with double-checked locking pattern.
78-
- Removed value-based class annotations.
80+
- Replaced `StableValue.of()` with double-checked locking pattern.
81+
- Removed `@ValueBased` annotations.
7982
- Compatible with JDK 21.
8083

8184
## Security Considerations

json-compatibility-suite/src/main/java/jdk/sandbox/compatibility/JsonTestSuiteSummary.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static void main(String[] args) throws Exception {
3434
}
3535

3636
void generateConformanceReport() throws Exception {
37+
LOGGER.fine(() -> "Starting conformance report generation");
3738
TestResults results = runTests();
3839

3940
System.out.println("\n=== JSON Test Suite Conformance Report ===");
@@ -59,11 +60,13 @@ void generateConformanceReport() throws Exception {
5960
System.out.printf("Overall Conformance: %.1f%%%n", conformance);
6061

6162
if (!results.shouldPassButFailed.isEmpty()) {
63+
LOGGER.fine(() -> "Valid JSON that failed to parse count=" + results.shouldPassButFailed.size());
6264
System.out.println("\n⚠️ Valid JSON that failed to parse:");
6365
results.shouldPassButFailed.forEach(f -> System.out.println(" - " + f));
6466
}
65-
67+
6668
if (!results.shouldFailButPassed.isEmpty()) {
69+
LOGGER.fine(() -> "Invalid JSON that was incorrectly accepted count=" + results.shouldFailButPassed.size());
6770
System.out.println("\n⚠️ Invalid JSON that was incorrectly accepted:");
6871
results.shouldFailButPassed.forEach(f -> System.out.println(" - " + f));
6972
}
@@ -74,12 +77,14 @@ void generateConformanceReport() throws Exception {
7477
}
7578

7679
void generateJsonReport() throws Exception {
80+
LOGGER.fine(() -> "Starting JSON report generation");
7781
TestResults results = runTests();
7882
JsonObject report = createJsonReport(results);
7983
System.out.println(Json.toDisplayString(report, 2));
8084
}
8185

8286
private TestResults runTests() throws Exception {
87+
LOGGER.fine(() -> "Walking test files under: " + TEST_DIR.toAbsolutePath());
8388
if (!Files.exists(TEST_DIR)) {
8489
throw new RuntimeException("Test suite not downloaded. Run: ./mvnw clean compile generate-test-resources -pl json-compatibility-suite");
8590
}
@@ -92,31 +97,39 @@ private TestResults runTests() throws Exception {
9297
int nPass = 0, nFail = 0;
9398
int iAccept = 0, iReject = 0;
9499

95-
var files = Files.walk(TEST_DIR)
96-
.filter(p -> p.toString().endsWith(".json"))
97-
.sorted()
98-
.toList();
100+
List<Path> files;
101+
try (var stream = Files.walk(TEST_DIR)) {
102+
files = stream
103+
.filter(p -> p.toString().endsWith(".json"))
104+
.sorted()
105+
.toList();
106+
}
107+
LOGGER.fine(() -> "Discovered JSON test files: " + files.size());
99108

100109
for (Path file : files) {
101110
String filename = file.getFileName().toString();
102-
String content = null;
103-
char[] charContent = null;
111+
String content;
112+
char[] charContent;
113+
final Path filePathForLog = file;
114+
LOGGER.fine(() -> "Processing file: " + filePathForLog);
104115

105116
try {
106117
content = Files.readString(file, StandardCharsets.UTF_8);
107118
charContent = content.toCharArray();
108119
} catch (MalformedInputException e) {
109-
LOGGER.warning("UTF-8 failed for " + filename + ", using robust encoding detection");
120+
LOGGER.finer(()->"UTF-8 failed for " + filename + ", using robust encoding detection");
110121
try {
111122
byte[] rawBytes = Files.readAllBytes(file);
112123
charContent = RobustCharDecoder.decodeToChars(rawBytes, filename);
113124
} catch (Exception ex) {
114-
throw new RuntimeException("Failed to read test file " + filename + " - this is a fundamental I/O failure, not an encoding issue: " + ex.getMessage(), ex);
125+
skippedFiles.add(filename);
126+
LOGGER.fine(() -> "Skipping unreadable file: " + filename + " due to: " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
127+
continue;
115128
}
116129
}
117130

118131
// Test with char[] API (always available)
119-
boolean parseSucceeded = false;
132+
boolean parseSucceeded;
120133
try {
121134
Json.parse(charContent);
122135
parseSucceeded = true;
@@ -126,6 +139,8 @@ private TestResults runTests() throws Exception {
126139
LOGGER.warning("StackOverflowError on file: " + filename);
127140
parseSucceeded = false; // Treat as parse failure
128141
}
142+
final boolean parseResultForLog = parseSucceeded;
143+
LOGGER.fine(() -> "Parsed " + filename + ": " + (parseResultForLog ? "SUCCESS" : "FAIL"));
129144

130145
// Update counters based on results
131146
if (parseSucceeded) {
@@ -148,7 +163,13 @@ private TestResults runTests() throws Exception {
148163
}
149164
}
150165
}
151-
166+
final int yPassF = yPass;
167+
final int yFailF = yFail;
168+
final int nPassF = nPass;
169+
final int nFailF = nFail;
170+
final int iAcceptF = iAccept;
171+
final int iRejectF = iReject;
172+
LOGGER.fine(() -> "Finished processing files. yPass=" + yPassF + ", yFail=" + yFailF + ", nPass=" + nPassF + ", nFail=" + nFailF + ", iAccept=" + iAcceptF + ", iReject=" + iRejectF);
152173
return new TestResults(files.size(), skippedFiles.size(),
153174
yPass, yFail, nPass, nFail, iAccept, iReject,
154175
shouldPassButFailed, shouldFailButPassed, skippedFiles);

json-java21-schema/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@
6464
<version>2.15.0</version>
6565
<scope>test</scope>
6666
</dependency>
67+
68+
<dependency>
69+
<groupId>net.jqwik</groupId>
70+
<artifactId>jqwik</artifactId>
71+
<version>1.9.3</version>
72+
<scope>test</scope>
73+
</dependency>
74+
6775
</dependencies>
6876

6977
<build>

json-java21-schema/src/test/java/io/github/simbo1905/json/schema/JsonSchemaLoggingConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void enableJulDebug() {
1717
try {
1818
targetLevel = Level.parse(levelProp.trim().toUpperCase(Locale.ROOT));
1919
} catch (IllegalArgumentException ignored) {
20-
targetLevel = Level.INFO;
20+
System.err.println("Unrecognized logging level from 'java.util.logging.ConsoleHandler.level': " + levelProp);
2121
}
2222
}
2323
}

json-java21/src/test/java/jdk/sandbox/java/util/json/ReadmeDemoTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ void quickStartExample() {
2020
JsonObject obj = (JsonObject) value;
2121
assertThat(((JsonString) obj.members().get("name")).value()).isEqualTo("Alice");
2222
assertThat(((JsonNumber) obj.members().get("age")).toNumber()).isEqualTo(30L);
23+
24+
String roundTrip = value.toString();
25+
assertThat(roundTrip).isEqualTo(jsonString);
2326
}
2427

2528
// Domain model using records
@@ -221,4 +224,4 @@ void displayFormattingExample() {
221224
assertThat(formatted).contains(" ]");
222225
assertThat(formatted).contains("}");
223226
}
224-
}
227+
}

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
<download-maven-plugin.version>1.7.1</download-maven-plugin.version>
6060
</properties>
6161

62-
63-
6462
<dependencyManagement>
6563
<dependencies>
6664
<dependency>

0 commit comments

Comments
 (0)