Skip to content
Open
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 micro-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>13.1.0</version>
<version>13.2.0</version>
</dependency>
</dependencies>
<configuration>
Expand Down Expand Up @@ -286,12 +286,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
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.1.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
Loading