Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java.lang.VerifyError / uninitialized register

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, experimenting with type conversions I'm having some trouble.


In assignment context narrowing primitive followed by boxing conversion should be allowed according to JLS (fi is a constant expression at compile time of type int, variable B is of type Byte and 0 is representable in the type byte), instead I get an error at runtime.


$ javac AssignmentTest.java
$ java AssignmentTest ### java version: "1.5.0_15"
Exception in thread "main" java.lang.VerifyError: (class: AssignmentTest, method: main signature: ([Ljava/lang/String;)V) Accessing value from uninitialized register 3



Would you please explain what's going on?

Thanks

P.S.
Btw, JLS also says that "the only exceptions that an assignment conversion may cause are OutOfMemoryError, ClassCastException and NullPointerException", VerifyError is not even mentioned.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try to initialize the variable that holds the byte data type?
 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I don't understand. Are you talking about the comment at line 08 in my original post? In this case I think I have nothing to initialize, because the conversion narrowing + boxing happens automatically and in one step, or at least it should (but maybe is just here where I'm wrong...).



Doing the conversion in two steps solves the problem, but I think that my original B = fi; should work too, and automatically in one step only.
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The strangest thing happened. I ran your code and got the same error. Then tinkered a little bit..

first did B = (byte)fi; which eliminated the error.

then added the following..



Then I replaced the file contents with your original code and even closed the command line. But now it's compiling and running fine! Can't reproduce the error now!
 
Hector Tenedero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what happened too during my first try. That's why I was asking if you can try to initialize the Byte data object since an uninitialized error was thrown by eclipse
 
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does it say in the API about VerifyError?

Too complicated a question for beginners: moving.
 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this error is something I can't fix easily or without alchemy (Gamini I'm talking to you ;-).
At this point I don't even *really* care why the verifier complains, API says it probably it's about an internal inconsistency and I'm fine with this. Most important thing I'd like to know: is this error triggered by me due to an incorrect use of one step narrowing + boxing conversion in assignment context? Or to put it another way, I thought the original program should run out-of-the box but it doesn't. Is it my fault?

Thank you again!
 
Campbell Ritchie
Marshal
Posts: 70370
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Try printing the bytecode with

javap -c MyClass

See how that compares with narrowing initialisation and boxing in two stages.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having the same error with JDK 6u12. javap gives:



The problem is related to line 9, where an integer is loaded from variable #2. It should be our 'fi' variable. But the value is never stored there!
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As 'fi' is a run-time constant, it should not be loaded via iload, but inlined and used as iconst_0... When I compile the file with Eclipse, the javap output is:


which makes much more sense: 0 is assigned to 'fi' in lines 9-10 and then 0 is inlined when 'fi' is used as assignment to B (line 11). I wonder why the output of Eclipse compiler is different...
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, by line numbers I mean the ones in the bytecode ;)
 
Sheriff
Posts: 22004
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adam Michalik wrote:As 'fi' is a run-time constant, it should not be loaded via iload, but inlined and used as iconst_0...


I'm sure you mean that fi is a compile time constant.
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you're right, Rob. It's not easy to write a reasonable post on a Friday afternoon, five minutes before leaving work
Anyway, I would say that the latter bytecode is correct... Any ideas how come that once the (standalone) compiler generates bytecode #1 and the other time (Eclipse) #2?
 
Adam Michalik
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have posted a bug to the Sun Java Bug Database: Bug ID = 6816548.
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic