FAQ
Hello,

I use cayenne 2.0.4, tomcat 5.5 and jdk 1.5.
I generated (cgen) a superclass (_Basket) and a subclass (Basket) with no
problem and use them in a standard servlet. I even can create instances and
commit changes to the database. It all works fine.

But in certain circumstandes I get a java.lang.ClassFormatError (at most
"Invalid SourceFile attribute at constant pool index 63") in one of the
three classes depending on where I first of all access a java.util.List via
get(...).

For example in _Basket this would crash:

getObjectId().getIdSnapshot().get("foo")

or in my servlet:

List baskets = DataContext.createDataContext().performQuery(query);
Basket basket = (Basket) baskets.get(0);

I spent the last two days on that problem and meanwhile tested it at three
different machines (win2000, xp, suse). It's always the same.

Can somebody give me a hint? What I not tested yet is instead of using
cayenne.jar using the lighter version and put the dependencies on my own.
But could that really be the problem?

Thanks for helping, Andreas Bobek.

Search Discussions

  • Malcolm Edgar at Apr 14, 2008 at 7:25 am
    I would recommend including a stracktrace of the error, to help debug this.

    regards Malcolm Edgar
    On Mon, Apr 14, 2008 at 1:34 PM, Andreas Bobek wrote:

    Hello,

    I use cayenne 2.0.4, tomcat 5.5 and jdk 1.5.
    I generated (cgen) a superclass (_Basket) and a subclass (Basket) with no
    problem and use them in a standard servlet. I even can create instances
    and
    commit changes to the database. It all works fine.

    But in certain circumstandes I get a java.lang.ClassFormatError (at most
    "Invalid SourceFile attribute at constant pool index 63") in one of the
    three classes depending on where I first of all access a java.util.List
    via
    get(...).

    For example in _Basket this would crash:

    getObjectId().getIdSnapshot().get("foo")

    or in my servlet:

    List baskets = DataContext.createDataContext().performQuery(query);
    Basket basket = (Basket) baskets.get(0);

    I spent the last two days on that problem and meanwhile tested it at three
    different machines (win2000, xp, suse). It's always the same.

    Can somebody give me a hint? What I not tested yet is instead of using
    cayenne.jar using the lighter version and put the dependencies on my own.
    But could that really be the problem?

    Thanks for helping, Andreas Bobek.
  • Andreas Bobek at Apr 14, 2008 at 2:11 pm
    I really don't get it, here is how I can reproduce this error:

    Shop => Servlet
    _Basket => Superclass
    Basket => Subclass

    Basket has no additional declarations.

    Shop creates a new Basket (within doGet...):

    Basket basket = (Basket)
    DataContext.createDataContext().createAndRegisterNewObject(Basket.class);

    _Basket contains this additional method (please don't care of the sense of
    this code, it is here for demonstration only, this code is even never
    called):

    public String test() {
    String name = ((DbAttribute)
    Configuration.getSharedConfiguration()

    .getDomain("na-domain").getMap("Basket").getObjEntity("Basket")
    .getDbEntity().getPrimaryKey().get(0)).getName();
    return (getObjectId().getIdSnapshot().get(name).toString());
    }


    Scenario 1: as described above => ClassFormatError (see below)

    Scenario 2: slightly modified the test method in _Basket:

    public String test() {
    Configuration conf = Configuration.getSharedConfiguration();
    String name = ((DbAttribute) conf

    .getDomain("na-domain").getMap("Basket").getObjEntity("Basket")
    .getDbEntity().getPrimaryKey().get(0)).getName();
    return (getObjectId().getIdSnapshot().get(name).toString());
    }

    => it works!

    Scenario 3: remove the creation of the new Basket object in Shop servlet =>
    it works independent of what is desclared in _Basket. I suppose this is
    because the class is never loaded.


    The stack trace:

    java.lang.ClassFormatError: Invalid this class index 2414 in constant pool
    in class file test/cayenne/_Basket
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClass(Unknown Source)
    java.security.SecureClassLoader.defineClass(Unknown Source)

    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLo
    ader.java:1629)

    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.jav
    a:850)

    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav
    a:1299)

    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav
    a:1181)
    java.lang.ClassLoader.loadClassInternal(Unknown Source)
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClass(Unknown Source)
    java.security.SecureClassLoader.defineClass(Unknown Source)

    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLo
    ader.java:1629)

    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.jav
    a:850)

    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav
    a:1299)

    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav
    a:1181)
    java.lang.ClassLoader.loadClassInternal(Unknown Source)
    test.Shop.serveEmptyForm(Shop.java:75)
    test.Shop.doGet(Shop.java:47)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


    I suppose it is a version issue.
    Tested on three machines, tomcat 5.5, jdk 1.5, cayenne 2.0.4

    Thanks, Andreas.
  • Andreas Bobek at Apr 14, 2008 at 11:20 pm
    Ok I finally found the mistake I made. It has neither something to do with
    Cayenne nor with Tomcat nor whatever. When building my project I use Ant and
    I had a build file with a copy statement and a filter token expression which
    was also applied to the binary class files...

    http://ant.apache.org/manual/CoreTypes/filterset.html

    Note: When a filterset is used in an operation, the files are processed in
    text mode and the filters applied line by line. This means that the copy
    operations will typically corrupt binary files. When applying filters you
    should ensure that the set of files being filtered are all text files.

    It tooks me quite long, original file and filtered file had exactly the same
    length. There was only one different byte value...

    (BTW: I never intended to replace filter text in binaries ;-)

    Andreas.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedApr 14, '08 at 5:39a
activeApr 14, '08 at 11:20p
posts4
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase