• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jasper Report Throws ClassFormatError: Unknown constant tag

 
Alex Lieb
Ranch Hand
Posts: 60
3
Java Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing work on a web application, and one of its functions is to read in jasper files as templates and produce reports for people to look at.

All of them work! Except 1! This is the code that's breaking!



This is the stack trace:

java.lang.ClassFormatError: Unknown constant tag 32 in class file <Unknown>
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:800)
java.lang.ClassLoader.defineClass(ClassLoader.java:643)
dori.jasper.engine.util.JRClassLoader.loadClassFromBytes(JRClassLoader.java:139)
dori.jasper.engine.fill.JRBaseFiller.loadCalculator(JRBaseFiller.java:537)
dori.jasper.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:299)
dori.jasper.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:109)
dori.jasper.engine.fill.JRFiller.fillReport(JRFiller.java:138)
dori.jasper.engine.JasperFillManager.fillReport(JasperFillManager.java:348)
com.visualgap.biz.reports.ReportFactory.createReport(ReportFactory.java:49)

I'm using Struts 1.2, also.

So far I've tried taking the byte array out of the 'report' variable, truncating it to 65535, and putting it back in, because somewhere else on the interwebs it said Jasper Reports have a size limit. I read that somewhere along the line the byte array gets converted into some format that can't have more than 65535 characters, and the byte stream for this file contains about 13200 indices after it's read in. After some testing I'm pretty sure that isn't actually the issue, but it was interesting to try anyway. It told me the file had been corrupted, probably because it was missing about half the bytes, and I was expecting that, but when I told it to only load in, say, 9000 bytes, it threw the same error, which tells me that the file size is either not the problem here, or it's throwing the file size-related error somewhere after it verifies that the file is complete. It seems likely that the file size isn't the problem though, because it then occurred to me that I should probably look at the other templates that were working, and... A lot of them are larger than the problem file. So it probably isn't that I guess.

But if it's not that, I'm not really sure what it could be? I've never seen an unknown constant tag issue before; the internet seems to say it means a lot of things, but the most common thread is that it indicates that a class file has been corrupted somehow. I'm not really sure how that's possible though because all the other reports (which are working) call the exact same classes and methods as this one. So now I'm looking for information about java classloader stuff to learn more about constant pools, but I'm still not really sure if I'm even heading in the right direction. I'm actually not even sure if I'm posting this on the right forum because I'm not 100% sure what kind of issue this is. So my question is; has anyone seen anything like this before, and does anyone know if this is an issue with Struts, Jasper, or my implementation of one or both of those things?

EDIT: It looks increasingly like there has to be something wrong with a compiled class file, but I'm not sure how to tell which class file it's unable to load.

EDIT 2: In case it's helpful; in debug mode when you highlight the line that throws the error, it gives a different error message: Can't assign dori.jasper.engine.JasperReport to dori.jasper.engine.JasperReport
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haven't encountered your problem when I used Jasper Reports.

But did you compile your report?


Your JRLoader.loadObject line just loads the report I think


Another possible reason is that the Jasper library does not match with the report software you use for creating those templates.

Looking further at the stack trace, I believe the class it was trying to use is missing/corrupted OR something in the report template needs "formatting" like date/number which Jasper doesn't know how to format.
 
Alex Lieb
Ranch Hand
Posts: 60
3
Java Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Your JRLoader.loadObject line just loads the report I think

The JRLoader line is working fine; but I think you're right, it's increasingly looking like one of my jar files is bad. It miraculously worked in the live test environment, but only when I was using my computer, strangely. So I still don't know what the deal is, but we at least know it *can* work the way it's set up now. So it's not a formatting/template issue, the report is compiled correctly, and all those things are right. The libraries for the test environment are all the same too; so the only real difference between the test environment and my environment is the test environment is currently running java 5 and I'm running java 7... Also the test is running Tomat 5 and I'm using Tomcat 7. Wait... Actually that's probably the first thing I should have looked into...

Apparently it's not actually that important though; my boss told me not to worry about it; I guess he's pushing to have that whole feature removed from the site because it's almost never used? Like; it generates a sales report for something that we've sold 1 of in the past few months. So if anyone's got any idea why it's doing this, it would still be good to understand why, but there's zero time sensitivity at this point, which is pretty cool. Coding is more fun when it's not time sensitive.
 
Tony Docherty
Saloon Keeper
Posts: 3142
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It miraculously worked in the live test environment, but only when I was using my computer, strangely.

Check the classpath settings on your computer and on a computer that doesn't work. It may be you are loading a different version of a jar file or loading the jar files in a different order.
 
Alex Lieb
Ranch Hand
Posts: 60
3
Java Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Check the classpath settings on your computer and on a computer that doesn't work. It may be you are loading a different version of a jar file or loading the jar files in a different order.

The test and local environments are loading the same jars in the same order, but I didn't do a byte-for-byte comparison of the jars, so unfortunately I think it's not impossible that there's a problem with multiple jars floating around that are named the same thing but meant for 32 and 64 bit systems respectively. I don't think that's what's causing *this* specific issue because if it were, this would be breaking in a number of other ways, and it wouldn't just be this one report, but thanks for bringing that up. I'm going to look at the naming of all those files more closely in the future because if any of the ambiguously named ones DO get mixed up like that, it's not just going to break one link, it's going to break everything.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!