0

I have recently been struggling to find the source a fatal error message that my program keeps showing:

Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 65

I've tried many things already, including: deleting all of the class files and rebuilding them, copying the entire project into a new project, upgrading my version of Eclipse (from Kepler to Luna), and modifying the code around where the line number that the error message gives. Nothing has worked, and I've ruled out the editor as other java projects run just fine. I would greatly appreciate it if you would let me know a way to solve this.

My code can be found here. The error has something to do with the Chunk class but what it is specifically I honestly do not know. The stack trace of the error message is:

at ca.ajweeks.igmc2014.level.Level.<init>(Level.java:22)
at ca.ajweeks.igmc2014.state.GameState.init(GameState.java:36)
at ca.ajweeks.igmc2014.state.StateManager.init(StateManager.java:34)
at ca.ajweeks.igmc2014.state.StateManager.<init>(StateManager.java:29)
at ca.ajweeks.igmc2014.Game.<init>(Game.java:38)
at ca.ajweeks.igmc2014.Game.main(Game.java:51)

EDIT: The source of the error seems to have been a pesky try-with-resources statement in the readFile method in the Chunk Class. I don't know if there is a bug in the current version of java that was causing this, or something to do with my specific program, either way using a normal try-catch block does the trick. Thanks everyone for the help!

AJ Weeks
  • 29
  • 6
  • Have you already read through http://stackoverflow.com/questions/100107/reasons-of-getting-a-java-lang-verifyerror? – azurefrog Nov 11 '14 at 22:55
  • it would drive me crazy too :) have you tried simplifying line `22` in `Level` ? You are creating an array of arrays of `Chunk` objects where each `Chunk` gets initialized with put-together Strings and ints and all in one line! If I where you, I'd instantiate the objects first, then create my arrays and afterwards put it all together – in as many lines as necessary. Then your Exception should show you something more concrete where to look. Sorry, if I didn't find you error.. Out of interest, why are you using `"levels/"+String.valueOf(level)` instead of `"levels/"+levels` ? – GameDroids Nov 11 '14 at 22:55
  • In theory you should not be able to cause that particular flavor of VerifyError (inconsistent stack map) without modifying the .class file somehow. This could be because you have some sort of profiling tool that is "massaging" the .class files, perhaps built into the IDE. The one odd possibility is that you've got two different versions of another class referenced from the failing one -- one version referenced during compile and the other when executing. – Hot Licks Nov 11 '14 at 23:10
  • @GameDroids Yes I have tried simplifying/modifying that line and it didn't help at all. I originally did have `"levels/"+levels` but tried changing it to `"levels/"+String.valueOf(level)` in an attempt to find the bug. Unfortunately that didn't help but thanks anyway. – AJ Weeks Nov 13 '14 at 22:05
  • @HotLicks I did attempt to implement BugSnag at one point but I thought that I removed it completely. I also had Slick2D implemented earlier but I also removed that completely (as far as I know). My `Java Build Path` only has the JRE System Libraries and nothing else... I just installed a fresh version of Eclipse as well so there couldn't be any 3rd party tools "massaging" as you said. – AJ Weeks Nov 13 '14 at 22:16
  • Try your code on a different box, one that you know has nothing "strange" on it. If you can get this to reproduce on a different box then it's almost certainly a legit Java bug. – Hot Licks Nov 13 '14 at 22:21
  • @HotLicks by "box" you mean another computer? If so, that is a good idea, I'll give it a shot. – AJ Weeks Nov 13 '14 at 22:28
  • Yep, a "clean" computer. If it fails there, work a bit to get it down to a minimal failing testcase. – Hot Licks Nov 13 '14 at 22:36
  • @HotLicks I cloned the project onto my laptop and got the same error message. This led me to attempt to narrow down the program as you recommended, and I found the bug!! It turns out that the try-with-resources was the cause of all this! GAH!!! After replacing that with a normal try-catch block the error message never appeared again. *Huge exhale.* Thank you for your advice, it really helped! Finally I can actually program again! – AJ Weeks Nov 13 '14 at 23:58
  • You should file a bug report with Oracle. – Hot Licks Nov 14 '14 at 00:05
  • (I can see how a bug relating to try-with-resources could have snuck through, since both that and the stackmap are somewhat clumsy distortions of the basic Java bytecode model, and so they would not be expected to play well together.) – Hot Licks Nov 14 '14 at 00:27
  • After further hunting it seems there may be no java bug after all. I put the try-with-resources block back into use with a change later on in the code. In my original code, in the Chunk class I returned a `new Tile[0][0];` in the readFile method. I replaced that with `new Tile[][] { { } };`. My intention with that code is to return an empty array if the file is empty or not found, just so I at least have an instantiated object to work with. Using the second statement seems to somehow fix the problem. Do you understand why this is, or do you think that is a bug with java? – AJ Weeks Nov 14 '14 at 01:01
  • I'm not real familiar with try-with-resources, since it was introduced after I worked on the verifier. But in general you're not supposed to be able to get a verify error except when the Java bytecodes have been corrupted somehow, and the only way I can see outside of switching referenced classes after compile or actually modifying the .class file would be a *javac* or JVM bug. I think it's a bug in Java. – Hot Licks Nov 15 '14 at 21:23

1 Answers1

0

If you would post relevant code here, that would save a lot of time along with the link to your code.

have a look at this thread Here A similar error and its solution, hope this helps.

SonalKhodiyar
  • 695
  • 8
  • 16