OpenJPA
  1. OpenJPA
  2. OPENJPA-1352

Merge fails if an entity has an element collection which is contructed using Arrays.asList

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-M3
    • Fix Version/s: 2.0.0-beta
    • Component/s: kernel
    • Labels:
      None

      Description

      When an entity has an element collection, which is constructed using Arrays.asList, the following exception is thrown:

      java.lang.IllegalAccessError:java.util.Arrays$ArrayList
      at java.lang.ClassLoader.defineClassImpl(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:265)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:202)
      at serp.bytecode.BCClassLoader.findClass(BCClassLoader.java:50)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
      at java.lang.Class.forNameImpl(Native Method)
      at java.lang.Class.forName(Class.java:169)
      at org.apache.openjpa.util.GeneratedClasses.loadBCClass(GeneratedClasses.java:67)
      at org.apache.openjpa.util.ProxyManagerImpl.getFactoryProxyCollection(ProxyManagerImpl.java:363)
      at org.apache.openjpa.util.ProxyManagerImpl.copyCollection(ProxyManagerImpl.java:182)
      at org.apache.openjpa.kernel.AttachStrategy.copyCollection(AttachStrategy.java:344)
      at org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:321)
      at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:218)
      at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251)
      at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:202)
      at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:153)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:104)
      at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3322)
      at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1176)
      at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:858)

        Activity

        Hide
        Fay Wang added a comment -

        Although Arrays.asList returns a List object, its class is Arrays.ArrayList. This is a static private inner class and can only be constructed from within Arrays. During merge/persist, openjpa needs to construct a proxyCollection by instantiating a new List object based on the class type of the original collection. This attempt fails because Arrays.ArrayList can not be loaded/constructed from outside Arrays.

        The attached patch is to return null value if the class can not be loaded instead of throwing the exception. A test case will be attached later.

        Show
        Fay Wang added a comment - Although Arrays.asList returns a List object, its class is Arrays.ArrayList. This is a static private inner class and can only be constructed from within Arrays. During merge/persist, openjpa needs to construct a proxyCollection by instantiating a new List object based on the class type of the original collection. This attempt fails because Arrays.ArrayList can not be loaded/constructed from outside Arrays. The attached patch is to return null value if the class can not be loaded instead of throwing the exception. A test case will be attached later.
        Hide
        Fay Wang added a comment -

        A new patch is checked into trunk (r-825700), which captures the exception and tries alternative way to instantiate proxyCollection/Map.

        Show
        Fay Wang added a comment - A new patch is checked into trunk (r-825700), which captures the exception and tries alternative way to instantiate proxyCollection/Map.

          People

          • Assignee:
            Fay Wang
            Reporter:
            Fay Wang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development