Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<property name="format" value="^(?!(.*(Map|List|Set))$).+$"/>
<property name="tokens" value="PARAMETER_DEF, VARIABLE_DEF, PATTERN_VARIABLE_DEF, RECORD_COMPONENT_DEF, LAMBDA"/>
</module>
<!-- Name classes correctly and don't use generic name for everything -->
<module name="IllegalIdentifierName">
<property name="format" value="^(?!(.*(Helper|Util))$).+$"/>
<property name="tokens" value=" CLASS_DEF"/>
</module>
<module name="IllegalImport"/>
<module name="InterfaceIsType"/>
<module name="JavadocStyle">
Expand Down
32 changes: 31 additions & 1 deletion .config/pmd/java/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
<rule ref="category/java/errorprone.xml/CollectionTypeMismatch"/>
<rule ref="category/java/errorprone.xml/ComparisonWithNaN"/>
<rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/>
<rule ref="category/java/errorprone.xml/DontImportSun"/>
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
<rule ref="category/java/errorprone.xml/EqualsNull"/>
<rule ref="category/java/errorprone.xml/IdempotentOperations"/>
Expand All @@ -164,6 +163,7 @@
<rule ref="category/java/errorprone.xml/SingletonClassReturningNewInstance"/>
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
<rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/>
<rule ref="category/java/errorprone.xml/UnsupportedJdkApiUsage"/>
<rule ref="category/java/errorprone.xml/UselessPureMethodCall"/>


Expand Down Expand Up @@ -208,6 +208,36 @@
<rule ref="category/java/security.xml"/>


<rule name="AvoidOptionalGet"
language="java"
message="Avoid using Optional#get"
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
externalInfoUrl="https://stackoverflow.com/a/49159955">
<description>
`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.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//MethodCall[pmd-java:matchesSig('java.util.Optional#get()')]
]]>
</value>
</property>
</properties>
</rule>

<rule name="AvoidStringBuilderOrBuffer"
language="java"
message="StringBuilder/StringBuffer should not be used"
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.0.0</version>
<version>13.2.0</version>
</dependency>
</dependencies>
<configuration>
Expand Down Expand Up @@ -83,12 +83,12 @@
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>7.20.0</version>
<version>7.21.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>7.20.0</version>
<version>7.21.0</version>
</dependency>
</dependencies>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion template-placeholder-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<version>3.15.0</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>
Expand Down
8 changes: 4 additions & 4 deletions template-placeholder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
<version>3.15.0</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>
Expand Down Expand Up @@ -215,7 +215,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.0.0</version>
<version>13.2.0</version>
</dependency>
</dependencies>
<configuration>
Expand Down Expand Up @@ -253,12 +253,12 @@
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>7.20.0</version>
<version>7.21.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>7.20.0</version>
<version>7.21.0</version>
</dependency>
</dependencies>
</plugin>
Expand Down