JDK-4421469 : toString method on self-referential collections causes stack overflow.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-03-03
  • Updated: 2021-03-03
  • Resolved: 2001-11-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.4.0Fixed 1.4.1 hopperFixed
Related Reports
Relates :  
Description
   As per bug 4419250, trying to print a self-referential collections causes infinite recursion (stack overflow).

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper merlin-beta2 merlin-rc1 FIXED IN: hopper merlin-rc1 INTEGRATED IN: hopper merlin-rc1 VERIFIED IN: hopper merlin-rc1
14-06-2004

PUBLIC COMMENTS Now if collection/map references itself, (this collection)/(this map) will be printed instead of the recursive call.
10-06-2004

EVALUATION I closed 4419250 as a duplicate, but then had a change of heart. Since it's impossible to reopen a bug that was closed as a duplicate, I filed a new bug, The general problem (comparison, hashing and printing of self-referential collections) is not solvable, but this special case is. I think that it would be worthwhile for the toString method in AbstactMap and AbstractSet to look for simple self-reference, substitute the string "(this collection)" or "(this map)" for the recursive invocation. To reiterate, this would not solve the general problem! But it would catch the simplest possible case of self-reference, and could aid substanbtially in debugging. joshua.bloch@Eng 2001-03-03
03-03-2001