JDK-6736248 : EnumEditor bug. Class check incorrect
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2008-08-12
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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.
JDK 7 Other
7 b46Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
openjdk version "1.6.0-internal"
OpenJDK Runtime Environment (build 1.6.0-internal-langel_02_jun_2008_10_58-b00)
OpenJDK Server VM (build 10.0-b19, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
$ uname -a
Linux towel.yyz.redhat.com 2.6.25.9-76.fc9.i686 #1 SMP Fri Jun 27 16:14:35 EDT 2008 i686 i686 i386 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
maven2 must be installed

A DESCRIPTION OF THE PROBLEM :
download: http://www.opennms.org/~brozow/enum-spring-test.tar.gz
install maven2. untar and run:
$ mvn test -e


Reference: http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=181

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
download: http://www.opennms.org/~brozow/enum-spring-test.tar.gz
install maven2. untar and run:
$ mvn test -e


Reference: http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=181

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No Failures
ACTUAL -
1 Failure




ERROR MESSAGES/STACK TRACES THAT OCCUR :
-------------------------------------------------------------------------------
Test set: org.openjdk.test.BeanWrapperTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.189 sec <<<
FAILURE!
testBeanWrapper(org.openjdk.test.BeanWrapperTest)  Time elapsed: 0.13 sec  <<<
ERROR!
org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property
value of type [java.lang.String] to required type
[org.openjdk.test.RelativeTime] for property 'time'; nested exception is
java.lang.IllegalArgumentException: Unsupported value: YESTERDAY
        at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:855)
        at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
        at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
        at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
        at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:55)
        at
org.openjdk.test.BeanWrapperTest.testBeanWrapper(BeanWrapperTest.java:30)
Caused by: java.lang.IllegalArgumentException: Unsupported value: YESTERDAY
        at sun.beans.editors.EnumEditor.setValue(EnumEditor.java:71)
        at sun.beans.editors.EnumEditor.setAsText(EnumEditor.java:101)
        at
org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:374)
        at
org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:350)
        at
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173)
        at
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
        at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:832)
        ... 31 more


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
download: http://www.opennms.org/~brozow/enum-spring-test.tar.gz
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
--- openjdkold/jdk/src/share/classes/sun/beans/editors/EnumEditor.java  2008-07-10 15:57:13.000000000 -0400
+++ openjdk/jdk/src/share/classes/sun/beans/editors/EnumEditor.java     2008-08-11 15:07:05.000000000 -0400
@@ -67,7 +67,7 @@
     }

     public void setValue( Object value ) {
-        if ( ( value != null ) && ( this.type != value.getClass() ) ) {
+       if ( ( value != null ) && ! ( this.type.isInstance( value ) ) ) {
             throw new IllegalArgumentException( "Unsupported value: " + value );
         }
         Object oldValue;

Comments
EVALUATION The Enum class allows to create constants that extend methods. For every constant the subclass is generated. So we should check that the value is assignable to the specific Enum class.
25-12-2008