[jbossseam-issues] [JBoss JIRA] Closed: (JBSEAM-4169) Enum converter does not handle inner anonymous enums

Norman Richards (JIRA) jira-events at lists.jboss.org
Mon May 11 15:22:46 EDT 2009


     [ https://jira.jboss.org/jira/browse/JBSEAM-4169?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Norman Richards closed JBSEAM-4169.
-----------------------------------

    Fix Version/s: 2.1.2
       Resolution: Done


Fixed. Thanks.

> Enum converter does not handle inner anonymous enums
> ----------------------------------------------------
>
>                 Key: JBSEAM-4169
>                 URL: https://jira.jboss.org/jira/browse/JBSEAM-4169
>             Project: Seam
>          Issue Type: Bug
>    Affects Versions: 2.1.1.GA
>         Environment: JBoss 5.0.1.GA, JDK 6u13, Seam 2.1.1.GA
>            Reporter: Adam Michalik
>            Assignee: Norman Richards
>             Fix For: 2.1.2
>
>
> The XHTML:
> <h:selectManyListbox value="#{testBean.tests}">
> 	<s:selectItems value="#{testLister.tests}" noSelectionLabel="" var="test" label="#{test}"/>
> 	<s:convertEnum/>
> </h:selectManyListbox>
> testLister returns a Set<Test>, testBean.set/getTests operates on List<Test>.
> The Test enum:
> package test;
> public enum Test {
> 	TEST,
> 	TEST_ANON {
> 		
> 	};
> }
> Enum converter fails with:
> java.lang.IllegalArgumentException with message: "test.Test$1 is not an enum type"
> java.lang.Class.enumConstantDirectory(Class.java:2965)
> java.lang.Enum.valueOf(Enum.java:191)
> org.jboss.seam.ui.converter.EnumConverter.getAsObject(EnumConverter.java:44)
> org.jboss.seam.ui.converter.PrioritizableConverter.getAsObject(PrioritizableConverter.java:61)
> org.jboss.seam.ui.converter.ConverterChain.getAsObject(ConverterChain.java:110)
> This is caused by the converter code:
> else if (val instanceof Collection) {
> 	t = ((Collection) val).iterator().next().getClass();
> 	return Enum.valueOf(t, value);
> }
> When t is an anonymous inner enum, the Enum.valueOf cannot be invoked properly.
> Cf.:
> package test;
> public enum Test {
> 	TEST,
> 	TEST_ANON {
> 		
> 	};
> 	
> 	
> 	public static void main(String[] args) {
> 		System.out.println(Test.TEST.getClass());  // prints "class test.Test"
> 		Class c1 = Test.TEST.getClass();
> 		System.out.println(Enum.valueOf(c1, "TEST")); // prints "TEST"
> 		System.out.println(Test.TEST_ANON.getClass()); // prints "class test.Test$1"
> 		Class c2 = Test.TEST_ANON.getClass();
> 		System.out.println(Enum.valueOf(c2, "TEST_ANON"));  // java.lang.IllegalArgumentException: test.Test$1 is not an enum type
> 	} 
> 	
> }
> Solution would be to use Enum's getDeclaringClass().

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list