Added PMD Rules for Singleton pattern violations. #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.