Skip to content

Commit e40df36

Browse files
Flossyclaude
andcommitted
fix: Allow -1 as sentinel value for heapUsedBytes in ResourceSnapshot
Problem: - ResourceSnapshot constructor rejected ALL negative values for heapUsedBytes - ApplicationResourceMonitor.estimateHeapUsage() returns -1 to indicate "not available" (per-application heap tracking requires JVMTI instrumentation) - This caused constructor to throw IllegalArgumentException when creating snapshots - CRITICAL bug preventing resource monitoring from working Solution: - Modified validation to allow -1 as special sentinel value - Changed: if (heapUsedBytes < 0) to if (heapUsedBytes < -1) - Updated error message to clarify -1 is allowed for N/A - Follows standard monitoring convention where -1 = "not available" Benefits: - Fixes crash in ApplicationResourceMonitor.collectMetrics() - Allows resource monitoring to work without heap tracking instrumentation - Follows common monitoring conventions (-1 for unavailable metrics) - Still validates against invalid negative values (< -1) Location: jplatform-api/src/main/java/org/flossware/jplatform/api/ResourceSnapshot.java:57-60 Closes #126 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b5554c1 commit e40df36

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

jplatform-api/src/main/java/org/flossware/jplatform/api/ResourceSnapshot.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public ResourceSnapshot(long timestamp, long cpuTimeNanos, long heapUsedBytes,
5454
if (cpuTimeNanos < 0) {
5555
throw new IllegalArgumentException("cpuTimeNanos cannot be negative: " + cpuTimeNanos);
5656
}
57-
if (heapUsedBytes < 0) {
58-
throw new IllegalArgumentException("heapUsedBytes cannot be negative: " + heapUsedBytes);
57+
// Allow -1 to indicate "not available", but reject other negative values
58+
if (heapUsedBytes < -1) {
59+
throw new IllegalArgumentException("heapUsedBytes cannot be negative (except -1 for N/A): " + heapUsedBytes);
5960
}
6061
if (threadCount < 0) {
6162
throw new IllegalArgumentException("threadCount cannot be negative: " + threadCount);

0 commit comments

Comments
 (0)