aspose file tools*
The moose likes Beginning Java and the fly likes Java Polyphormismus BUG (solved: not a bug:-) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Polyphormismus BUG (solved: not a bug:-)" Watch "Java Polyphormismus BUG (solved: not a bug:-)" New topic
Author

Java Polyphormismus BUG (solved: not a bug:-)

Mathias Schneider
Greenhorn

Joined: Oct 29, 2008
Posts: 5
Hi,

you will believe me to have discovered a bug because I have a small example for evidence!

I discoverd somehow a real bug in Java that is:

Instance variables are not updated if the polyphormismus has overwritten the instance value in the case another class is instanciated during the polyphormismus method that calls back on that instancevariable.

Please explain me how that is possible... I have 3 Classes:






___________

Although variable b is set to true in ClassA the output of b in value() is false!

[ November 02, 2008: Message edited by: Mathias Schneider ]
[ November 04, 2008: Message edited by: Mathias Schneider ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18855
    
  40

Please explain me how that is possible... I have 3 Classes:


Yea, there seems to be a lot of ofuscation going on... but it just boils down to this.

During construction, the super() constructor is executed first, then the instance variables (and initializers), then the rest of the constructor. In this example, the third part is not relevent (since it is empty). But take a look at the first two parts...

The b variable is set to true, via the super() constructor, calling a method, via the overridden method. The instance assignment comes next -- which means that it is assigned to false. Basically, the assignment to false, on the declaration line, is done after the variable is assigned to true, in the overridden method. This is not a bug. It is defined in the specification to work that way.

Henry
[ November 02, 2008: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mathias Schneider
Greenhorn

Joined: Oct 29, 2008
Posts: 5
Thanks a lot ;-)

I wrote this topic a bit too fast because after debugging I solved the "problem" of overwriting the value of the isntance variable.

As I also know what is going on I can only aggree.

The order of constructor is crucial: First the superconstor is called which sets the variable to "true". After that the instance variable in ClassA is initialized with "false" (this is where the change is "overwritten") and after that the constructor of ClassA is executed... but this doen't change anything (as you have said, since it is empty).

[ November 04, 2008: Message edited by: Mathias Schneider ]
[ November 04, 2008: Message edited by: Mathias Schneider ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Polyphormismus BUG (solved: not a bug:-)