beanshell2
beanshell2 copied to clipboard
Overriding a method which is invoked from super-constructor issues a NPE
Adapted from
http://sourceforge.net/tracker/?func=detail&aid=2081602&group_id=4075&atid=10407
5
If two classes defined in script extend each other, and you overwrite a method
which is called from the super constructor a NullPointerException is issued.
Example code:
{{{
public class A {
int _id;
public A (int id) {
setId(id);
}
public void setId (int id) {
_id = id;
}
public int getId() { return _id; }
}
public class B extends A {
public B (int id) {
super (id * 3);
}
public void setId (int id) {
super.setId(id * 5);
}
}
print(new B(1).getId());
}}}
Original issue reported on code.google.com by [email protected] on 27 Feb 2011 at 10:36
test case is bsh.SourceForgeIssuesTest#sourceforge_issue_2081602
Original comment by [email protected] on 27 Feb 2011 at 10:42
Created a patch - seems a bit risky.
Need more test cases first.
Original comment by [email protected] on 27 Feb 2011 at 10:44
Attachments:
Another test case, with an abstract class.
Original comment by [email protected] on 31 Aug 2012 at 1:34
Attachments: