In my current project I am making extensive use of dependency injection using Guice. More specifically I am using member injection to inject objects into the member variables of a class. In java member variables should usually be private, but this is even more important when using injection as the whole purpose of injecting members is to remove explicit dependencies and make code more modular. However, try as I might I cannot remember to change all my protected injected variables to private. Therefore I ended up just creating a PMD rule to the same effect.

<rule name="PrivateInjections" message="Please make injected fields private"

	<description>We don't take kindly to non private injected fields round
			these parts
		<property name="xpath">
     			<![CDATA[//ClassOrInterfaceBodyDeclaration [ 
			public String myParameter; //is bad

			public String myParameter; //is better

			private String myParameter; //is best