United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6736248 : EnumEditor bug. Class check incorrect

Details
Type:
Bug
Submit Date:
2008-08-12
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
linux
Sub-Component:
java.beans
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

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.
                                     
2008-12-25



Hardware and Software, Engineered to Work Together