Announcement Announcement Module
Collapse
No announcement yet.
Roo's toString aspect results in java.lang.OutOfMemoryError: Java heap space Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo's toString aspect results in java.lang.OutOfMemoryError: Java heap space

    This was a hard one to solve.

    The default Roo-generated toString() method:

    Code:
    privileged aspect Proposal_Roo_ToString {
        
        public String Proposal.toString() {
            return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
        }
        
    }
    resulted in this error:
    Code:
    java.lang.OutOfMemoryError: Java heap space
    	at java.util.Arrays.copyOf(Arrays.java:2367)
    	at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
    	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
    	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415)
    	at java.lang.StringBuilder.append(StringBuilder.java:132)
    	at java.lang.StringBuilder.append(StringBuilder.java:128)
    	at java.util.AbstractCollection.toString(AbstractCollection.java:450)
    	at org.hibernate.collection.PersistentBag.toString(PersistentBag.java:507)
    	at java.lang.String.valueOf(String.java:2902)
    	at java.lang.StringBuffer.append(StringBuffer.java:232)
    	at org.apache.commons.lang3.builder.ToStringStyle.appendDetail(ToStringStyle.java:598)
    	at org.apache.commons.lang3.builder.ToStringStyle.appendInternal(ToStringStyle.java:473)
    	at org.apache.commons.lang3.builder.ToStringStyle.append(ToStringStyle.java:436)
    	at org.apache.commons.lang3.builder.ToStringBuilder.append(ToStringBuilder.java:848)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.appendFieldsIn(ReflectionToStringBuilder.java:528)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:689)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:288)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:151)
    	at edu.wisc.acadprop.domain.ProposalType_Roo_ToString.ajc$interMethod$edu_wisc_acadprop_domain_ProposalType_Roo_ToString$edu_wisc_acadprop_domain_ProposalType$toString(ProposalType_Roo_ToString.aj:13)
    	at edu.wisc.acadprop.domain.ProposalType.toString(ProposalType.java:1)
    	at java.lang.String.valueOf(String.java:2902)
    	at java.lang.StringBuffer.append(StringBuffer.java:232)
    	at org.apache.commons.lang3.builder.ToStringStyle.appendDetail(ToStringStyle.java:586)
    	at org.apache.commons.lang3.builder.ToStringStyle.appendInternal(ToStringStyle.java:550)
    	at org.apache.commons.lang3.builder.ToStringStyle.append(ToStringStyle.java:436)
    	at org.apache.commons.lang3.builder.ToStringBuilder.append(ToStringBuilder.java:848)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.appendFieldsIn(ReflectionToStringBuilder.java:528)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:689)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:288)
    	at org.apache.commons.lang3.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:151)
    	at edu.wisc.acadprop.domain.Proposal_Roo_ToString.ajc$interMethod$edu_wisc_acadprop_domain_Proposal_Roo_ToString$edu_wisc_acadprop_domain_Proposal$toString(Proposal_Roo_ToString.aj:13)
    	at edu.wisc.acadprop.domain.Proposal.toString(Proposal.java:1)
    The problem originated in the Roo-generated display.tagx file here:

    Code:
       <c:set var="sec_object" value="${fn:escapeXml(object)}" />
    where toString() is called.

    I assume that as the ReflectionToStringBuilder moved down the object graph, it eventually exceeded the memory. By adding an 'excludedFields' property to @RooToString and adding any object fields, the problem was stopped.

    Has anyone else run into this? Is there a way to stop this from happening other than added object fields to the excludedFields list?
    Last edited by lili5058; Feb 8th, 2012, 03:24 PM.

  • #2
    We are reliant now on the commons-lang3 ReflectionToStringBuilder as we don't need to determine what fields are required for the toString method anymore. You're workaround is valid and also you can push in the toString method yourself to prevent its generation in the ITD.

    I've not hit this problem before so would you please attach a Roo script so that I can reproduce the issue?

    Thanks
    Alan
    Last edited by Alan Stewart; Feb 8th, 2012, 06:02 PM.

    Comment


    • #3
      Alan -- I won't be able to supply a Roo script since the entities etc. have been de-Roo'ed in many cases. The problem also started showing up when we finally had data in the database. The entity that generated the OutOfMemoryError and two files in a one-to-many relationship and those objects also have several one-to-many relationships, etc.

      It would seem that if the toString() method is looking at the whole object graph and recursively calling toString() on all objects by following the references, that String will get huge once that entity has real connections. I think that is what I was running up against.

      Comment


      • #4
        In this case, best to write your own toString() method if required

        Comment

        Working...
        X