-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Andy Wilkinson opened SPR-5577 and commented
I'm trying to get the dm Server 2.0 codebase working against Spring 3.0.0.M2 and have hit a problem
in StaticLabeledEnumResolver. There would appear to be a regression from 2.5.6.A. The problem's
probably best illustrated by the attached.
Assuming that you have the attached class and jar in the current directory, along with spring core's
jar and commons logging, the following should reproduce the problem:
java -classpath
.:com.springsource.org.apache.commons.logging-1.1.1.jar:org.springframework.core-3.0.0.M2.jar
StaticLabeledEnumResolverTest
Exception in thread "main" java.lang.NullPointerException
at
org.springframework.core.enums.AbstractCachingLabeledEnumResolver.getLabeledEnumByLabel(AbstractCachingLabeledEnumResolver.java:75)
at StaticLabeledEnumResolverTest.main(StaticLabeledEnumResolverTest.java:17)
Having looked at what's happening in the debugger it would appear that the first call to
CachingMapDecorator.get() adds a weakly-referenced value to the map, keyed by the enum class. With
nothing else referencing the value, garbage collection leaves the WeakReference pointing to null.
This then causes the NPE.
It's key that FooEnum.jar isn't on the claspath. If FooEnum.jar is on the classpath the NPE does not
occur as the weakly-referenced value is still strongly-referenced from elsewhere.
This is currently blocking a fairly major please of work that we had hoped to complete in our
current sprint: I'd really appreciate it if you could take a look at this ASAP.
Affects: 3.0 M2
Attachments:
- FooEnum.jar (637 bytes)
- StaticLabeledEnumResolverTest.class (1.31 kB)