spring-projects / spring-webflow

Spring Web Flow
https://spring.io/projects/spring-webflow
Apache License 2.0
331 stars 233 forks source link

Debug Logging causes StackOverflowError [SWF-1192] #403

Open spring-operator opened 14 years ago

spring-operator commented 14 years ago

Ron Eisele opened SWF-1192 and commented

Running an application with SWF 2.0.8 and Spring 3; filing issue in SWF since it seems the self-referential classes may be SWF's.

Setting the logging level for 'org.springframework' in our app causes a StackOverflowError with the following output (repeated continuously until final exception):

at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
at org.springframework.webflow.engine.impl.FlowSessionImpl.toString(FlowSessionImpl.java:245)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:107)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:72)
at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.toString(FlowExecutionImpl.java:322)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:100)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:87)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:66)
at org.springframework.core.style.StylerUtils.style(StylerUtils.java:47)
at org.springframework.webflow.core.collection.LocalAttributeMap.toString(LocalAttributeMap.java:336)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
at org.springframework.webflow.engine.impl.FlowSessionImpl.toString(FlowSessionImpl.java:245)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:107)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:72)
at org.springframework.core.style.DefaultToStringStyler.styleValue(DefaultToStringStyler.java:91)
at org.springframework.core.style.DefaultToStringStyler.styleField(DefaultToStringStyler.java:79)
at org.springframework.core.style.ToStringCreator.append(ToStringCreator.java:156)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.toString(FlowExecutionImpl.java:322)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:100)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:87)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:66)
at org.springframework.core.style.StylerUtils.style(StylerUtils.java:47)
at org.springframework.webflow.core.collection.LocalAttributeMap.toString(LocalAttributeMap.java:336)
at java.lang.String.valueOf(String.java:2826)
at org.springframework.core.style.DefaultValueStyler.style(DefaultValueStyler.java:78)

Affects: 2.0.8

spring-operator commented 14 years ago

Eugene Voytitsky commented

Just an opinion (cause some time ago I also developed a some kind of ToStringifier).

ToStringCreator is a simple but powerful Spring solution for generating toString() representation for any Java obj which doesn't have pretty-printing implemented toString(). But it seems that ToStringCreator doesn't track cycles in objects graph. This means that having cycled object graph (A->B->C->A: means instance A references instance B which in turn references instance C and so on) then any attempt to pretty-print any of A, B, C via ToStringCreator will cause similar StackOverflowError.

In your stacktrace above we see such a cycle: org.springframework.webflow.core.collection.LocalAttributeMap -> org.springframework.webflow.engine.impl.FlowExecutionImpl -> org.springframework.webflow.engine.impl.FlowSessionImpl -> org.springframework.webflow.core.collection.LocalAttributeMap (of course I mean that instances of the correspondent classes have a cycle not the classes)

Solutions:

  1. ToStringCreator should track the cycles. But tracking the cycles will overweight the simple and lightweight ToStringCreator.
  2. All src code which uses ToStringCreator should never pass object involved in cycled objects graph to ToStringCreator for pretty-printing. (Because the 2-nd one couldn't be guaranteed because codebase of src relying on Spring is a big enough then the only 1-st option may really fix a problem)

Workaround for you: Just turn off logging level for 'org.springframework' back. I don't see any other solution for the moment.

HTH