beanshell2 icon indicating copy to clipboard operation
beanshell2 copied to clipboard

Overriding a method which is invoked from super-constructor issues a NPE

Open GoogleCodeExporter opened this issue 10 years ago • 3 comments

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

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter

test case is bsh.SourceForgeIssuesTest#sourceforge_issue_2081602

Original comment by [email protected] on 27 Feb 2011 at 10:42

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter

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:

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter

Another test case, with an abstract class.

Original comment by [email protected] on 31 Aug 2012 at 1:34

Attachments:

GoogleCodeExporter avatar Apr 22 '15 19:04 GoogleCodeExporter