diff --git a/.config/checkstyle/checkstyle.xml b/.config/checkstyle/checkstyle.xml index 463a629a..262c9f91 100644 --- a/.config/checkstyle/checkstyle.xml +++ b/.config/checkstyle/checkstyle.xml @@ -79,6 +79,11 @@ + + + + + diff --git a/.config/pmd/java/ruleset.xml b/.config/pmd/java/ruleset.xml index e96576b1..9dc7a0fa 100644 --- a/.config/pmd/java/ruleset.xml +++ b/.config/pmd/java/ruleset.xml @@ -146,7 +146,6 @@ - @@ -164,6 +163,7 @@ + @@ -208,6 +208,36 @@ + + +`Optional#get` can be interpreted as a getter by developers, however this is not the case as it throws an exception when empty. + +It should be replaced by +* doing a mapping directly using `.map` or `.ifPresent` +* using the preferred `.orElseThrow`, `.orElse` or `.or` methods + +Java Developer Brian Goetz also writes regarding this topic: + +> Java 8 was a huge improvement to the platform, but one of the few mistakes we made was the naming of `Optional.get()`, because the name just invites people to call it without calling `isPresent()`, undermining the whole point of using `Optional` in the first place. +> +> During the Java 9 time frame, we proposed to deprecate `Optional.get()`, but the public response to that was ... let's say cold. As a smaller step, we introduced `orElseThrow()` in 10 (see [JDK-8140281](https://bugs.openjdk.java.net/browse/JDK-8140281)) as a more transparently named synonym for the current pernicious behavior of `get()`. IDEs warn on unconditional use of `get()`, but not on `orElseThrow()`, which is a step forward in teaching people to code better. The question is, in a sense, a "glass half empty" view of the current situation; `get()` is still problematic. + + 3 + + + + + + + + + com.puppycrawl.tools checkstyle - 13.0.0 + 13.2.0 @@ -83,12 +83,12 @@ net.sourceforge.pmd pmd-core - 7.20.0 + 7.21.0 net.sourceforge.pmd pmd-java - 7.20.0 + 7.21.0 diff --git a/template-placeholder-demo/pom.xml b/template-placeholder-demo/pom.xml index 05b947bc..06fc3187 100644 --- a/template-placeholder-demo/pom.xml +++ b/template-placeholder-demo/pom.xml @@ -44,7 +44,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.14.1 + 3.15.0 ${maven.compiler.release} diff --git a/template-placeholder/pom.xml b/template-placeholder/pom.xml index 3738a65c..9e08842f 100644 --- a/template-placeholder/pom.xml +++ b/template-placeholder/pom.xml @@ -97,7 +97,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.14.1 + 3.15.0 ${maven.compiler.release} @@ -215,7 +215,7 @@ com.puppycrawl.tools checkstyle - 13.0.0 + 13.2.0 @@ -253,12 +253,12 @@ net.sourceforge.pmd pmd-core - 7.20.0 + 7.21.0 net.sourceforge.pmd pmd-java - 7.20.0 + 7.21.0