[BCEL-info]BCEL query on helloify.java
Brought to you by:
dahm
|
From: Derek M. <d.j...@sm...> - 2003-12-01 11:55:23
|
I am currently undertaking a project to animate java=20
programs by analysing bytecode method calls and attribute updates. I=20
have been studying the BCEL API as a means of implementing my design. I=20
am however having difficulty understanding results when running the=20
program on the latest JDK virtual machine. I wonder if anyone could help =
clarify this.
I have been experimenting with the helloify.java program which I can=20
get working in most cases but I get the following error when executing=20
it on the java program which i have included below.
"Exception in thread "main" java.lang.VerifyError: (class:=20
ComplexNumber_hello, method: add signature:=20
(LComplexNumber;)LComplexNumber;) Incompatible type for getting or=20
setting field"
My java program simply creates two complexNumber objects and adds them=20
together. This compiles and runs successfully on "Java(TM) 2 Runtime=20
Environment, Standard Edition (build 1.4.2_02-b03), Java HotSpot(TM)=20
Client VM (build 1.4.2_02-b03, mixed mode)". The=20
ComplexNumber_hello.class file produces the error above and I cannot=20
understand why. It seems to happen when trying to return the sum of the=20
two complex numbers. I have tried to rectify this problem with no=20
success. When using the Kaffe JVM supplied with RedHat Linux 7.2 I get=20
no errors when running ComplexNumber_hello or ComplexNumber classes. Is=20
this an issue with the latest JVM or am I missing something important?
Thanks.
/*
* Class ComplexNumber specify Complex Number object and
* associated functions
*
*/
class ComplexNumber {
// Private data fields for the complex number:
// realPart + imagPart * i
private double realPart;
private double imagPart;
=20
=20
/**
* initializes the
* the complex number to be zero.
*/
ComplexNumber() {
realPart =3D 0;
imagPart =3D 0;
}
/**
* Constructor that allows the real and imaginary
* parts of the complex number to be initialized
* to arbitrary values.
*/
ComplexNumber(double realPart, double imagPart) {
this.realPart =3D realPart;
this.imagPart =3D imagPart;
}
/**
* Set the value of a complex number by specifying its
* real and imaginary parts.
*/
public void setValue(double realPart, double imagPart) {
this.realPart =3D realPart;
this.imagPart =3D imagPart;
}
/**
* Return a new complex number with its value equal
* to the sum of the invoking ComplexNumber and
* the Complex Number argument.
*/
public ComplexNumber add(ComplexNumber theNum) {
return new ComplexNumber(realPart + theNum.realPart,
imagPart + theNum.imagPart);
} =20
/**
* Convert the complex number into a string representation.
* The string representation is realPart + imagPart i.
*/
public String toString() {
// If the imagPart is >=3D 0 print out a + b i
if (imagPart >=3D 0) {
return realPart + " + " + imagPart + " i";
}
// If the imagPart is < 0 print out a - b i
else {
return realPart + " - " + (-imagPart) + " i";
}
}
=20
//***********************************************************************=
**
// Test the above methods
=20
public static void main(String args[]) {
=20
// Create 3 complex number objects and initialize
ComplexNumber A =3D new ComplexNumber();
ComplexNumber B =3D new ComplexNumber();
ComplexNumber result =3D new ComplexNumber();
System.out.println("Testing ComplexNumber.java...");
=20
A.setValue(5,1);
B.setValue(2,3);
=20
// Test the add method
result =3D A.add(B); =20
=20
// output the result
System.out.println(A.toString() + " + " + B.toString() + " =20
=3D " + result.toString());
=20
}
}
|