Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363749 - Remove recursion from IdentityWeakHashMap$WeakEntry.clone()
Summary: Remove recursion from IdentityWeakHashMap$WeakEntry.clone()
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: David Minsky CLA
QA Contact: Project Inbox CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-14 15:54 EST by David Minsky CLA
Modified: 2022-06-09 10:10 EDT (History)
0 users

See Also:


Attachments
Fix (1.23 KB, patch)
2011-11-14 15:54 EST, David Minsky CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Minsky CLA 2011-11-14 15:54:43 EST
Created attachment 206989 [details]
Fix

Current code for WeakEntry.clone() (inner class in IdentityWeakHashMap) is recursive:

protected Object clone(ReferenceQueue refQueue) {
    return new WeakEntry<K,V>(hash, key.get(), value.get(), ((next == null) ? null : (WeakEntry<K,V>)next.clone(refQueue)), refQueue);
}

Recursive cloning in the product can potentially cause a stack overflow with a large set of data and a normal stack size configuration. Ideally, recursion should not be used when cloning.

Propoing to change the code to:

protected Object clone(ReferenceQueue refQueue) {
    WeakEntry current = this;
    WeakEntry root = new WeakEntry(current.hash, current.key.get(), current.value.get(), null, refQueue);
    WeakEntry currentClone = root;

    while (current.next != null) {
        currentClone.next = new WeakEntry(current.next.hash, current.next.key.get(), current.next.value.get(), null, refQueue);
        current = current.next;
        currentClone = currentClone.next;
    }

    return root;
}
Comment 1 David Minsky CLA 2011-11-15 10:45:10 EST
As an addition, this is related to the work done in:

Bug 237812 - RECURSION IN IDENTITYHASHSET.CLONE() CAN CAUSE STACK OVERFLOW WITH LARGE SET
Comment 2 David Minsky CLA 2011-11-15 10:50:29 EST
Fixed in trunk (2.4) at revision: 10395
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:10:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink