|
Finder idea to detect overloading pitfall: msg#00034java.findbugs.general
Hello, this one is not easy to describe. I hope I make the point clear. If not please ask. In principal it is a more general form of the http://findbugs.sourceforge.net/bugDescriptions.html#EQ_SELF_NO_OBJECT bug pattern. If we have 2 classes class A and B where class A extends B and class A contains a method taking objects of class A as argument, an there is also a method that takes objects of class B (or any base type of A) as argument (overloaded) than the latter method should call instanceoff and delegate to the method taking objects of class A as argument if the passed object is instance off class A. Example: class B { } class A extends B { void foo(A a) { System.out.println("A"); } void foo(B b) { // if this if is missing and the code is // different to foo(A) than FindBugs should // complain. if (b instanceof A) { foo((A) b); } System.out.println("B"); } } Otherwise new A().foo((B) new A()) will behave strange and print out B. This is due to the fact that the linking of this calls is done during compiletime and not during runtime. A common instance of this bug is a equals method that takes Object instances as argument: void boolean equals (A a) { ... } void boolean equals (Object obj) { return false; } Got the point? Might be worth to write a FindBugs checker for this? Regards, Andreas.
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Finder Idea for servlets facing multithreading issues, Andreas Mandel |
|---|---|
| Next by Date: | annotated blocks in Java method code, Eugene Kuleshov |
| Previous by Thread: | Finder Idea for servlets facing multithreading issues, Andreas Mandel |
| Next by Thread: | annotated blocks in Java method code, Eugene Kuleshov |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |