|
42 | 42 | <rule ref="category/java/codestyle.xml/NoPackage"/> |
43 | 43 | <rule ref="category/java/codestyle.xml/PrematureDeclaration"/> |
44 | 44 | <rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/> |
| 45 | + <rule ref="category/java/codestyle.xml/VariableCanBeInlined"/> |
45 | 46 |
|
46 | 47 | <rule ref="category/java/design.xml"> |
47 | 48 | <!-- Sometimes abstract classes have just fields --> |
|
138 | 139 | <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/> |
139 | 140 | <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/> |
140 | 141 | <rule ref="category/java/errorprone.xml/BrokenNullCheck"/> |
| 142 | + <rule ref="category/java/errorprone.xml/CollectionTypeMismatch"/> |
141 | 143 | <rule ref="category/java/errorprone.xml/ComparisonWithNaN"/> |
142 | 144 | <rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/> |
143 | 145 | <rule ref="category/java/errorprone.xml/DontImportSun"/> |
|
155 | 157 | <rule ref="category/java/errorprone.xml/SingletonClassReturningNewInstance"/> |
156 | 158 | <rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/> |
157 | 159 | <rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/> |
158 | | - <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/> |
| 160 | + <rule ref="category/java/errorprone.xml/UselessPureMethodCall"/> |
159 | 161 |
|
160 | 162 |
|
161 | 163 | <rule ref="category/java/multithreading.xml"> |
|
218 | 220 | </properties> |
219 | 221 | </rule> |
220 | 222 |
|
| 223 | + <rule name="AvoidPostConstruct" |
| 224 | + language="java" |
| 225 | + message="Avoid @PostConstruct" |
| 226 | + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"> |
| 227 | + <description> |
| 228 | + Using a `@PostConstruct` method is usually only done when field injection is used and initialization needs to be performed after that. |
| 229 | + |
| 230 | + It's better to do this directly in the constructor with constructor injection, so that all logic will be encapsulated there. |
| 231 | + This also makes using the bean in environments where JavaEE is not present - for example in tests - a lot easier, as forgetting to call the `@PostConstruct` method is no longer possible. |
| 232 | + </description> |
| 233 | + <priority>3</priority> |
| 234 | + <properties> |
| 235 | + <property name="xpath"> |
| 236 | + <value> |
| 237 | + <![CDATA[ |
| 238 | +//MethodDeclaration[pmd-java:hasAnnotation('jakarta.annotation.PostConstruct')] |
| 239 | +]]> |
| 240 | + </value> |
| 241 | + </property> |
| 242 | + </properties> |
| 243 | + </rule> |
| 244 | + |
| 245 | + <rule name="AvoidPreDestroy" |
| 246 | + language="java" |
| 247 | + message="Avoid @PreDestroy" |
| 248 | + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"> |
| 249 | + <description> |
| 250 | + `@PreDestroy` should be replaced by implementing `AutoCloseable` and overwriting the `close` method instead. |
| 251 | + |
| 252 | + This also makes using the bean in environments where JavaEE is not present - for example in tests - a lot easier, as forgetting to call the `@PreDestroy` method is no much more difficult. |
| 253 | + </description> |
| 254 | + <priority>3</priority> |
| 255 | + <properties> |
| 256 | + <property name="xpath"> |
| 257 | + <value> |
| 258 | + <![CDATA[ |
| 259 | +//MethodDeclaration[pmd-java:hasAnnotation('jakarta.annotation.PreDestroy')] |
| 260 | +]]> |
| 261 | + </value> |
| 262 | + </property> |
| 263 | + </properties> |
| 264 | + </rule> |
| 265 | + |
| 266 | + <rule name="AvoidUnmanagedThreads" |
| 267 | + language="java" |
| 268 | + message="Avoid unmanaged threads" |
| 269 | + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"> |
| 270 | + <description> |
| 271 | + Trying to manually manage threads usually gets quickly out of control and may result in various problems like uncontrollable spawning of threads. |
| 272 | + Threads can also not be cancelled properly. |
| 273 | + |
| 274 | + Use managed Thread services like `ExecutorService` and `CompletableFuture` instead. |
| 275 | + </description> |
| 276 | + <priority>3</priority> |
| 277 | + <properties> |
| 278 | + <property name="xpath"> |
| 279 | + <value> |
| 280 | + <![CDATA[ |
| 281 | +//MethodCall[pmd-java:matchesSig('java.lang.Thread#start()') or pmd-java:matchesSig('java.lang.Thread#startVirtualThread(java.lang.Runnable)') or pmd-java:matchesSig('java.lang.Thread$Builder#start(java.lang.Runnable)')] |
| 282 | +]]> |
| 283 | + </value> |
| 284 | + </property> |
| 285 | + </properties> |
| 286 | + </rule> |
| 287 | + |
221 | 288 | <rule name="JavaObjectSerializationIsUnsafe" |
222 | 289 | language="java" |
223 | 290 | message="Using Java Object (De-)Serialization is unsafe and has led to too many security vulnerabilities" |
|
0 commit comments