[RFC] Fix StackOverflowError with TreePaths

Omair Majid omajid at redhat.com
Fri Apr 17 08:24:53 PDT 2009


Trying to encode a TreePath as XML can cause a StackOverflowError. The 
attached case SimpleTreePathTest.java is a simple reproducer.

The issue appears to be that when using the TreePath as a java bean, the 
  wrong constructor is picked. The TreePath in the example uses the 
constructor TreePath(Object []) but the constructor picked by the bean 
reflection mechanism is TreePath(Object). So instead of ["Path1", 
"Path2"] we get [["Path1", "Path2"]]. TreePaths are immutable and so one 
cant be converted into another. XMLEncoder then recursively tries to 
create a new TreePath to match the original, but cant, until it hits a 

The fix is to somehow ensure that the right constructor gets picked for 
creating a TreePath. The attached patch tries to pick a constructor with 
more array arugment matches. JDK7 uses another technique to solve this 
problem: the bean (in this case TreePath) uses annotation to indicate 
the constructor to use when creating the bean.

There were no regressions in any of the jtreg XMLEncoder tests after 
applying this patch. I am not sure about the performance impact of this 
change though.

Any objections/suggestions?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: SimpleTreePathTest.java
Type: text/x-java
Size: 466 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20090417/48fa1c54/SimpleTreePathTest.java 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: treepath-stackoverflow.patch
Type: text/x-patch
Size: 4343 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20090417/48fa1c54/treepath-stackoverflow.patch 

More information about the distro-pkg-dev mailing list