Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b135cb

Browse files
committedJul 2, 2021
chore(pmd): enable GuardLogStatement rule
Notes: - false positives were suppressed until we have PMD >= 6.36.0 (see #1250) - ThymeleafViewResolverInitializingBean: a check for null was removed because IDEA said that the result is always false because getBean() throws exception when there is no bean. I haven't add try-catch and let it fails in order to not miss such case (if it happens)
1 parent fe50e01 commit 0b135cb

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed
 

‎src/main/config/pmd.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<rule ref="category/java/bestpractices.xml/ConstantsInInterface" />
2222
<rule ref="category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt" />
2323
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach" />
24+
<rule ref="category/java/bestpractices.xml/GuardLogStatement">
25+
<properties>
26+
<property name="logLevels" value="trace,debug,info,warn,error" />
27+
<property name="guardsMethods" value="isTraceEnabled,isDebugEnabled,isInfoEnabled,isWarnEnabled,isErrorEnabled" />
28+
</properties>
29+
</rule>
2430
<!--<rule ref="category/java/bestpractices.xml/JUnit4SuitesShouldUseSuiteAnnotation" />-->
2531
<rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseAfterAnnotation" />
2632
<rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseBeforeAnnotation" />

‎src/main/java/ru/mystamps/web/feature/image/FilesystemImagePersistenceStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void init() {
5151
log.warn("Directory '{}' doesn't exist! Image uploading won't work", storageDir);
5252

5353
} else if (!storageDir.canWrite()) {
54-
log.warn(
54+
log.warn( // NOPMD: GuardLogStatement (https://github.com/pmd/pmd/issues/957)
5555
// FIXME(java9): log also user: ProcessHandle.current().info().user()
5656
"Directory '{}' exists but isn't writable for the current user! "
5757
+ "Image uploading won't work.",
@@ -69,7 +69,7 @@ public void init() {
6969

7070
} else if (!previewDir.canWrite()) {
7171
// FIXME(java9): log also user: ProcessHandle.current().info().user()
72-
log.warn(
72+
log.warn( // NOPMD: GuardLogStatement (https://github.com/pmd/pmd/issues/957)
7373
"Directory '{}' exists but isn't writable for the current user! "
7474
+ "Image preview generation won't work",
7575
previewDir

‎src/main/java/ru/mystamps/web/feature/series/DownloadImageInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean preHandle(
8989

9090
if (!(request instanceof StandardMultipartHttpServletRequest)) {
9191
// It could mean that <form> tag doesn't have enctype="multipart/form-data" attribute.
92-
LOG.warn(
92+
LOG.warn( // NOPMD: GuardLogStatement (https://github.com/pmd/pmd/issues/957)
9393
"Unknown type of request ({}). "
9494
+ "Downloading images from external servers won't work!",
9595
request

‎src/main/java/ru/mystamps/web/feature/series/HttpURLConnectionDownloaderService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public DownloadResult download(String fileUrl) {
117117
private static HttpURLConnection openConnection(URL url) throws IOException {
118118
URLConnection connection = url.openConnection();
119119
if (!(connection instanceof HttpURLConnection)) {
120-
LOG.warn(
120+
LOG.warn( // NOPMD: GuardLogStatement (https://github.com/pmd/pmd/issues/957)
121121
"Couldn't open connection: "
122122
+ "unknown type of connection class ({}). "
123123
+ "Downloading files from external servers won't work!",

‎src/main/java/ru/mystamps/web/support/spring/boot/ThymeleafViewResolverInitializingBean.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ public class ThymeleafViewResolverInitializingBean
6565
public void afterPropertiesSet() throws Exception {
6666
ThymeleafViewResolver viewResolver =
6767
applicationContext.getBean(ThymeleafViewResolver.class);
68-
if (viewResolver == null) {
69-
LOG.warn(
70-
"Cannot adjust ThymeleafViewResolver: "
71-
+ "bean of this type wasn't found in application context"
72-
);
73-
return;
74-
}
7568

7669
Profiles prod = Profiles.of("prod");
7770
boolean productionEnv = environment.acceptsProfiles(prod);

0 commit comments

Comments
 (0)
Please sign in to comment.