0 Replies Latest reply on May 25, 2006 11:19 AM by mjremijan

    v3.2.3 works fine, v4.0.3 I get ArrayStoreException. Why?

    mjremijan

      I am working on converting from v3.2.3 to version 4.0.3SP1. I've run into a weird problem where an ArrayStoreException is being thrown. The strange thing is it works fine in v3.2.3 running with the same sun jvm so I'm gussing there might be a class loader difference in 4.0.3SP1 which is causing the problem. Here's what's going on.

      I have an interface which simplifed looks like this:

      public interface OrderBy {
       public String getField();
      }


      Then I have an implementation which looks like this:

      public class ProductOrderBy implements OrderBy {
      
       public static ProductOrderBy NAME = new ProductOrderBy("name");
      
       private String field;
       private ProductOrderBy(String s) {
       field = s;
       }
       public String getField() {
       return field;
       }
      }

      So far this is pretty simple stuff, nothing too exciting here. I just have an interface, an implementation, and an exercise of the singleton pattern.

      Now, when I use this in my code what I do is create an array of OrderBy interfaces. So that code snippet looks like this:

      new OrderBy []{ProductOrderBy.NAME}


      There is nothing wrong with the code. It compiles fine and it should because ProductOrderBy implments the OrderBy interface so it should be able to be put into an OrderBy array.

      Now when I run in v3.2.3 everthing works fine. But now when I try to run in v4.0.3SP1 the creation of the array throws a java.lang.ArrayStoreException. So I'm quite puzzled about this.

      But it gets more weird. As an experiment I tried changing the static singleton:

      FROM THIS:
      public static ProductOrderBy NAME = new ProductOrderBy("name");


      TO THIS:
      public static OrderBy NAME = new ProductOrderBy("name");


      My though was if I defined the singleton as the interface instead of the implementing class it might help. But this didn't work either. I got a different error though. I got:
      javax.servlet.ServletException: loader constraints violated when linking org/moss/sql/OrderBy class.


      As a last effort I decided to try and change the way the array was created:

      FROM THIS:
      new OrderBy []{ProductOrderBy.NAME}


      TO THIS:
      new ProductOrderBy []{ProductOrderBy.NAME}


      Doing this works and I don't get any errors. So I guess it's a workaround to the problem but I still don't understand what the problem is. I believe it should work the way I had it, after all it does work fine in v3.2.3.

      My application deployment is very typical. It is an ear file which looks like this:

      /beans.jar --My ejb's, manifest class-path uses jars in /library
      /homesuite.war --My webapp
      /library/jar1.jar --classes used by the ejb's in beans.jar
      /library/jar2.jar
      /library/jar3.jar
      /meta-inf/application.xml
      /meta-inf/jboss-app.xml
      /meta-inf/Manifest.mf


      Now in my case, the OrderBy interface is located in two places. It's in the /library/jar1.jar file AND in the WEB-INF/lib/jar1.jar file inside the war. Everything's alwasy compiled together so there are no version issues. The implementation class ProductOrderBy is inside the beans.jar file. The bean.jar file is NOT in the WEB-INF/lib directory of the war.

      I hope this makes sense. I've tried to provide all the information I could. If anyone has any suggestions please let me know.

      Michael
      mjremijan@yahoo.com