Quantcast

PMD eclipse Plug-in - Can not Produce ConstructorCallsOverridableMethod Warning

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

PMD eclipse Plug-in - Can not Produce ConstructorCallsOverridableMethod Warning

Artium Nihamkin
Hi,

I installed the PMD plugin for eclipse from the update site.

Now I want to see if it catches the ConstructorCallsOverridableMethod on a test code I wrote. (before discovering that this rule exist, I had the intention to write it myself).

The warning is explained in the docs here: http://pmd.sourceforge.net/rules/java/design.html#ConstructorCallsOverridableMethod

My code is:

============================================
package test;

abstract class AbstractA {
    AbstractA() {
        System.out.println("A::constructor"); // NOPMD
        foo();
    }
   
    abstract void foo();
}
============================================
package test;

abstract class AbstractA {
    AbstractA() {
        System.out.println("A::constructor"); // NOPMD
        foo();
    }
   
    abstract void foo();
}
============================================
package test;
public class Sandbox {
    public static void main(final String[] args) {
        final AbstractA ab = new B();
    }
}
============================================


This code demonstrates the problem whith constructor that call a method that is overriden in the child class.

Next, I right click on the project in eclipse's "Package Explorer" and then choose PMD -> Generate Report. All the PMD configurations are out of the box default.
The resulting report is:

============================================
src/test/AbstractA.java:9    Use explicit scoping instead of the default package private level
src/test/B.java:4    Found non-transient, non-static member. Please mark as transient or provide accessors.
src/test/B.java:11    Use explicit scoping instead of the default package private level
src/test/Sandbox.java:2    All methods are static.  Consider using Singleton instead.  Alternatively, you could add a private constructor or make the class abstract to silence this warning.
src/test/Sandbox.java:7    Avoid variables with short names like ab
============================================

As you can see, the expected ConstructorCallsOverridableMethod warning is not present.

Am I doing something wrong here?


Thank you,
Artium


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Pmd-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/pmd-devel
Loading...