From e074761db3e2db94ae17f7c1db11223392cc39a7 Mon Sep 17 00:00:00 2001 From: Valera V Harseko Date: Wed, 8 Jul 2026 16:13:18 +0300 Subject: [PATCH] Synchronize overrides of synchronized methods (CodeQL java/non-sync-override) Four methods overrode a synchronized method from java.io.InputStream or java.lang.Throwable without carrying the synchronized modifier, so a caller that relies on the base-class locking contract loses it on these subtypes. Restore the modifier on each override: - ByteArrayBranchingStream.mark: the class already synchronizes read/skip/ available/reset, all of which share the position/mark fields; mark mutated mark from position without the lock, so add synchronized to match. - Value.OldValueInputStream.mark and reset: honour the InputStream contract for the ObjectInputStream used to decode a Value; both touch the shared _mark / _value._next cursor. - PersistitMap.PersistitMapException.getCause: honour the Throwable.getCause contract. Each method only reads or writes its own fields, so adding synchronized cannot introduce a lock-ordering deadlock, and single-threaded callers are unaffected. --- .../java/org/forgerock/http/io/ByteArrayBranchingStream.java | 3 ++- persistit/core/src/main/java/com/persistit/PersistitMap.java | 2 +- persistit/core/src/main/java/com/persistit/Value.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/commons/http-framework/core/src/main/java/org/forgerock/http/io/ByteArrayBranchingStream.java b/commons/http-framework/core/src/main/java/org/forgerock/http/io/ByteArrayBranchingStream.java index f5b09043b9..8c15b15451 100644 --- a/commons/http-framework/core/src/main/java/org/forgerock/http/io/ByteArrayBranchingStream.java +++ b/commons/http-framework/core/src/main/java/org/forgerock/http/io/ByteArrayBranchingStream.java @@ -13,6 +13,7 @@ * * Copyright 2010–2011 ApexIdentity Inc. * Portions Copyright 2011-2016 ForgeRock AS. + * Portions Copyrighted 2026 3A Systems, LLC */ package org.forgerock.http.io; @@ -102,7 +103,7 @@ public boolean markSupported() { } @Override - public void mark(int readlimit) { + public synchronized void mark(int readlimit) { mark = position; } diff --git a/persistit/core/src/main/java/com/persistit/PersistitMap.java b/persistit/core/src/main/java/com/persistit/PersistitMap.java index 6639524f49..4acdf1369b 100644 --- a/persistit/core/src/main/java/com/persistit/PersistitMap.java +++ b/persistit/core/src/main/java/com/persistit/PersistitMap.java @@ -741,7 +741,7 @@ public static class PersistitMapException extends RuntimeException { } @Override - public Throwable getCause() { + public synchronized Throwable getCause() { return _exception; } } diff --git a/persistit/core/src/main/java/com/persistit/Value.java b/persistit/core/src/main/java/com/persistit/Value.java index 7e7cdb1729..8f95cf61ec 100644 --- a/persistit/core/src/main/java/com/persistit/Value.java +++ b/persistit/core/src/main/java/com/persistit/Value.java @@ -5056,12 +5056,12 @@ protected final void readStreamHeader() throws IOException { } @Override - public void mark(final int readLimit) { + public synchronized void mark(final int readLimit) { _mark = _value._next; } @Override - public void reset() throws IOException { + public synchronized void reset() throws IOException { if (_mark < 0) { throw new IOException("No mark"); } else {