2009/10/8 John Harrop <jharrop...@gmail.com>:
>> java.lang.ClassFormatError: Unknown constant tag 52 in class file
>> queries__init (Trial.clj:0)
>
> Almost certainly, it occurs in some part of the code that works on a class's
> bytecodes either directly on disk or in the form of an unstructured Java
> byte array; hopefully that narrows it down to a few small areas of the total
> code base. Rewriting such code to treat a class as a more structured thing
> than just a byte array might be a useful long-term fix, and would help avoid
> other similar bugs, but would presumably be a *lot* of work. A short-term
> fix would be to check all index arithmetic in the same subset of the code,
> find the errors (of which apparently there are greater than zero), and fix
> them. An intermediate compromise would be to add bounds-checking logic
> (perhaps as asserts) to the same code, then use that and a source file that
> reproduces the bug to locate the indexing errors and fix them.

The exception type would indicate that the class file generated by the
clojure compiler is invalid. The exception message would indicate that
the offending bit of the class file is a tag in the constant pool.

A java class file has a section in it called the constant pool. The
pool contains things like class, field, and method names, string and
number literals, method signatures etc. and those constants are then
referenced from the actual byte code, e.g. a method call op code would
specify the target method with a constant pool index.

Each entry in the constant pool starts with a tag that indicates the
type of the entry. Valid tag values are (in the current class file
format) bytes with values 1, 3, 4, 5, 6, 7, 8, 9, 10 ,11 and 12. So
the tag value in the exception message is clearly invalid (52).

Why does the compiler produce invalid class files? I don't know, I
haven't looked into it. It might be a bug in the compiler or it might
be a bug in the byte code library that the compiler uses. Since there
is an effort to re-write the compiler in clojure, I don't think any
effort will be put into fixing this in the current compiler.

The class file format is defined here:
http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

The constant pool is defined in section 4.4.

-- 
  ! Lauri

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to