-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added PMD Rules for Singleton pattern violations. #21
Conversation
Added the rules in Design
Andreas Dangel » pmd #261 UNSTABLE |
Andreas Dangel » pmd #262 UNSTABLE |
Minor Bug Fix
Andreas Dangel » pmd #263 UNSTABLE |
Andreas Dangel » pmd #264 UNSTABLE |
Andreas Dangel » pmd #265 UNSTABLE |
Andreas Dangel » pmd #266 UNSTABLE |
Andreas Dangel » pmd #267 UNSTABLE |
Hi Andreas,
I have added two java rules for PMD and have run it against dogfood.xml to check any violations to the coding standard/quality. Explaining these rules in detail as below
SingleMethodSingletonRule: Rule that checks that a class following the Singleton Design pattern should have only 1 getInstance method and no overloaded copies of the method. The reason for this rule SIngleton Classes are intended to contain only one getInstance method. Developers may have added another getInstance method for test purposes but would have forgotten to remove them. This rule intends to catch those scenarios.
SingletonClassReturningNewInstance: A rule that checks if the getInstance method of the Singleton Class instantiates the data member instance of the class and does not return a locally created instance inside the getInstance method. The reason for this rule is that, Singleton classes are meant to instantiate their class variable and cache them than returning a locally created variable which is not cached. This does not conform to Singleton Design Pattern and the class essentially becomes a non-singleton class.
As these rules conform to a design pattern the rules have been added in design.xml ruleset of the PMD-java code.
The test cases have been added to the corresponding folders. Please have a look at it and let me know if you need additional information.