elharo commented on issue #1997:
URL: 
https://github.com/apache/maven-resolver/issues/1997#issuecomment-5064177136

   The issue reported in apache/maven-resolver #1997 is not a bug. No action 
should be taken to modify the code, and the issue should be closed as a false 
positive.
   
   The bug report claims that the fast-path get() operation in 
ConcurrentWeakCache contains a flaw where it can return a "stale reference" if 
the key is garbage collected immediately after the check. This claim is 
technically incorrect and contradicts Java's memory model and garbage 
collection mechanics for the following reasons:
   
       Strong References Prevent Garbage Collection: The caller of 
putIfAbsent(K key, V value) provides the key object as a method argument. 
Because the calling thread holds a strong reference to key on its execution 
stack, the Java Garbage Collector (GC) cannot collect the key while the method 
is executing.
   
       Safe Value Retrieval: When the fast-path executes V existing = get(key), 
the method extracts and returns the value. If the value is found, existing 
becomes a strong reference on the thread's stack. Once a strong reference is 
established, the object is protected from garbage collection.
   
       No "Stale" Strong References: Java does not return "stale" strong 
references. If the underlying data structure uses WeakReference or 
SoftReference, the act of unwrapping the reference yields either a valid, 
strong reference to the object or null (if the object was already collected). 
It is impossible to return a non-null reference that subsequently becomes 
invalid while still in scope.
   
   The fast-path optimization is correct by design. The issue was labeled as 
part of an "LLM grabbag" (#1944), indicating it is an automated finding. It is 
a hallucination of a concurrent race condition that does not exist in the JVM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to