Skip to content
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

Merged
merged 7 commits into from Apr 16, 2015

Conversation

kshantaramanUFL
Copy link

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.

kshantaraman and others added 2 commits April 13, 2015 16:06
@buildhive
Copy link

Andreas Dangel » pmd #261 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #262 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #263 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #264 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #265 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #266 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@buildhive
Copy link

Andreas Dangel » pmd #267 UNSTABLE
Looks like there's a problem with this pull request
(what's this?)

@adangel adangel merged commit 4080a0f into adangel:master Apr 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants