Announcement Announcement Module
Collapse
No announcement yet.
LinkedMap instead of LinkedHashMap when running Java1.6 for PropertyEditors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LinkedMap instead of LinkedHashMap when running Java1.6 for PropertyEditors

    I have fixed our problem but I have no idea why changing from Java 1.5 to Java 1.6 should case the following error.

    org.apache.commons.collections.map.LinkedMap cannot be cast to
    java.util.HashMap

    The code that was generating the problem was:
    Code:
    private Map<String, Object> mPropertyEditors = new HashMap<String, Object>();
    
    private void someFunction(Object aObject) {
       Map fieldNames = (HashMap)mPropertyEditors.get(aObject.getClass().getName());
    }
    under Java 1.5 the mPropertyEditors.get() returned a java.util.LinkedHashMap
    under java 1.6 it returns org.apache.commons.collections.map.LinkedMap

    Changing the cast to java.util.Map solves the issue but I do not understand why changing to Java 1.6 should cause this change.

    Any thoughts ?

  • #2
    You should always cast to an interface instead of a concrete implementation.

    Is this custom code or is it code somewhere in the spring framework? Spring does some detection of which collection implementation to use, based on jdk version and classpath. Also which version of spring does it concern? Spring < 2.5.x didn't contain any specific jdk 1.6 detection stuff. Check the CollectionFactory class for details.
    Last edited by Marten Deinum; Sep 30th, 2008, 01:57 PM.

    Comment


    • #3
      Spring 1.2.7

      You should always cast to an interface instead of a concrete implemention - Good point

      The class is a Controller that extends from org.springframework.web.servlet.mvc.SimpleFormCont roller.

      Looking furthur at our code I think the problem is in some lovely reflection code attempting to determine the appropiate getter method for some data.
      All private methods and no tests - lovely.

      Comment

      Working...
      X