This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-api.git


The following commit(s) were added to refs/heads/main by this push:
     new 89c05e9  NIFI-14890 Aligned Maven PMD configuration with standard NiFi 
Rules (#19)
89c05e9 is described below

commit 89c05e9dfd54c1b4ed59e70df3b4cd8e47ff4736
Author: dan-s1 <[email protected]>
AuthorDate: Tue Aug 26 22:04:16 2025 -0400

    NIFI-14890 Aligned Maven PMD configuration with standard NiFi Rules (#19)
    
    Signed-off-by: David Handermann <[email protected]>
---
 pmd-ruleset.xml                                    | 86 ++++++++++++++++++++++
 pom.xml                                            |  3 +
 .../apache/nifi/components/PropertyDescriptor.java |  2 +-
 .../resource/StandardResourceReferenceFactory.java |  2 +
 .../documentation/xml/XmlDocumentationWriter.java  |  1 +
 .../java/org/apache/nifi/flowfile/FlowFile.java    |  4 +-
 .../exception/TerminatedTaskException.java         |  3 -
 .../nifi/processor/util/StandardValidators.java    |  6 +-
 .../apache/nifi/registry/VariableDescriptor.java   |  2 +-
 .../java/org/apache/nifi/time/DurationFormat.java  |  4 +-
 10 files changed, 101 insertions(+), 12 deletions(-)

diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml
new file mode 100644
index 0000000..a131255
--- /dev/null
+++ b/pmd-ruleset.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<ruleset name="Maven PMD Plugin Ruleset"
+         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 
http://pmd.sourceforge.net/ruleset_2_0_0.xsd";>
+
+    <description>Default PMD Rules for Apache NiFi API</description>
+
+    <rule ref="category/java/bestpractices.xml/AvoidMessageDigestField" />
+    <rule ref="category/java/bestpractices.xml/AvoidReassigningCatchVariables" 
/>
+    <rule ref="category/java/bestpractices.xml/DoubleBraceInitialization" />
+    <rule ref="category/java/bestpractices.xml/ExhaustiveSwitchHasDefault" />
+    <rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach" />
+    <rule ref="category/java/bestpractices.xml/LooseCoupling" />
+    <rule ref="category/java/bestpractices.xml/MissingOverride" />
+    <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" 
/>
+    <rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
+    <rule ref="category/java/bestpractices.xml/UnusedPrivateField" />
+    <rule 
ref="category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation" />
+    <rule ref="category/java/bestpractices.xml/UnusedLocalVariable" />
+    <rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
+    <rule ref="category/java/bestpractices.xml/UseStandardCharsets" />
+
+    <rule ref="category/java/codestyle.xml/AvoidDollarSigns" />
+    <rule ref="category/java/codestyle.xml/ExtendsObject" />
+    <rule ref="category/java/codestyle.xml/IdenticalCatchBranches" />
+    <rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop" />
+    <rule ref="category/java/codestyle.xml/UnnecessaryConstructor" />
+    <rule ref="category/java/codestyle.xml/UnnecessaryImport" />
+    <rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
+    <rule ref="category/java/codestyle.xml/UnnecessarySemicolon" />
+    <rule ref="category/java/codestyle.xml/UseDiamondOperator" />
+    <rule ref="category/java/codestyle.xml/UseExplicitTypes" />
+
+    <rule ref="category/java/errorprone.xml/AvoidAssertAsIdentifier" />
+    <rule 
ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" 
/>
+    <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" />
+    <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" />
+    <rule ref="category/java/errorprone.xml/BrokenNullCheck" />
+    <rule ref="category/java/errorprone.xml/CheckSkipResult" />
+    <rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" />
+    <rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" />
+    <rule ref="category/java/errorprone.xml/EmptyCatchBlock" />
+    <rule ref="category/java/errorprone.xml/ImplicitSwitchFallThrough" />
+    <rule ref="category/java/errorprone.xml/JumbledIncrementer" />
+    <rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
+    <rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
+    <rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
+    <rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
+    <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
+
+    <rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
+    <rule ref="category/java/multithreading.xml/DontCallThreadRun" />
+    <rule ref="category/java/multithreading.xml/DoubleCheckedLocking" />
+    <rule ref="category/java/multithreading.xml/UnsynchronizedStaticFormatter" 
/>
+
+    <rule ref="category/java/performance.xml/BigIntegerInstantiation" />
+    <rule ref="category/java/performance.xml/InefficientEmptyStringCheck" />
+    <rule ref="category/java/performance.xml/StringInstantiation" />
+    <rule ref="category/java/performance.xml/StringToString" />
+    <rule ref="category/java/performance.xml/TooFewBranchesForSwitch">
+        <properties>
+            <property name="minimumNumberCaseForASwitch" value="2" />
+        </properties>
+    </rule>
+    <rule ref="category/java/performance.xml/UselessStringValueOf" />
+    <rule ref="category/java/performance.xml/UseStringBufferForStringAppends" 
/>
+</ruleset>
diff --git a/pom.xml b/pom.xml
index 3a4f368..b7bc01a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -249,6 +249,9 @@
                     <printFailingErrors>true</printFailingErrors>
                     <linkXRef>false</linkXRef>
                     <targetJdk>${maven.compiler.release}</targetJdk>
+                    <rulesets>
+                        
<ruleset>${maven.multiModuleProjectDirectory}/pmd-ruleset.xml</ruleset>
+                    </rulesets>
                 </configuration>
                 <executions>
                     <execution>
diff --git a/src/main/java/org/apache/nifi/components/PropertyDescriptor.java 
b/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
index 8f61545..213584d 100644
--- a/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
+++ b/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
@@ -428,7 +428,7 @@ public final class PropertyDescriptor implements 
Comparable<PropertyDescriptor>
          * @param <E>        generic parameter for an enum class, that may 
implement the DescribedValue interface
          * @return the builder
          */
-        public <E extends Enum<E>> Builder allowableValues(final EnumSet<E> 
enumValues) {
+        public <E extends Enum<E>> Builder allowableValues(final EnumSet<E> 
enumValues) { //NOPMD
             if (null != enumValues) {
                 this.allowableValues = enumValues.stream()
                         .map(enumValue -> enumValue instanceof DescribedValue 
describedValue
diff --git 
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
 
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
index 3980a9b..a0a477b 100644
--- 
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
+++ 
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
@@ -30,6 +30,7 @@ public class StandardResourceReferenceFactory implements 
ResourceReferenceFactor
 
     private static final ResourceReferences EMPTY_RESOURCE_REFERENCES = new 
StandardResourceReferences(Collections.emptyList());
 
+    @Override
     public ResourceReferences createResourceReferences(final String value, 
final ResourceDefinition resourceDefinition) {
         if (value == null) {
             return EMPTY_RESOURCE_REFERENCES;
@@ -52,6 +53,7 @@ public class StandardResourceReferenceFactory implements 
ResourceReferenceFactor
         return new StandardResourceReferences(references);
     }
 
+    @Override
     public ResourceReference createResourceReference(final String value, final 
ResourceDefinition resourceDefinition) {
         if (value == null) {
             return null;
diff --git 
a/src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java 
b/src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java
index 178fec5..dc3770b 100644
--- 
a/src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java
+++ 
b/src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java
@@ -401,6 +401,7 @@ public class XmlDocumentationWriter extends 
AbstractDocumentationWriter {
         writeEndElement();
     }
 
+    @Override
     protected void writeMultiProcessorUseCases(final 
List<MultiProcessorUseCase> multiProcessorUseCases) throws IOException {
         if (multiProcessorUseCases.isEmpty()) {
             return;
diff --git a/src/main/java/org/apache/nifi/flowfile/FlowFile.java 
b/src/main/java/org/apache/nifi/flowfile/FlowFile.java
index ef5f61e..cf2805d 100644
--- a/src/main/java/org/apache/nifi/flowfile/FlowFile.java
+++ b/src/main/java/org/apache/nifi/flowfile/FlowFile.java
@@ -120,14 +120,14 @@ public interface FlowFile extends Comparable<FlowFile> {
             if (key == null) {
                 throw new IllegalArgumentException("Invalid attribute key: 
null");
             }
-            if (key.trim().isEmpty()) {
+            if (key.isBlank()) {
                 throw new IllegalArgumentException("Invalid attribute key: 
<Empty String>");
             }
             return key;
         }
 
         public static boolean isValid(final String key) {
-            return key != null && !key.trim().isEmpty();
+            return key != null && !key.isBlank();
         }
     }
 }
diff --git 
a/src/main/java/org/apache/nifi/processor/exception/TerminatedTaskException.java
 
b/src/main/java/org/apache/nifi/processor/exception/TerminatedTaskException.java
index a55ed62..df2c413 100644
--- 
a/src/main/java/org/apache/nifi/processor/exception/TerminatedTaskException.java
+++ 
b/src/main/java/org/apache/nifi/processor/exception/TerminatedTaskException.java
@@ -31,7 +31,4 @@ import org.apache.nifi.processor.ProcessSessionFactory;
  * Process Sessions
  */
 public class TerminatedTaskException extends ProcessException {
-    public TerminatedTaskException() {
-        super();
-    }
 }
diff --git 
a/src/main/java/org/apache/nifi/processor/util/StandardValidators.java 
b/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
index c9d8a70..f24001a 100644
--- a/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
+++ b/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
@@ -224,7 +224,7 @@ public class StandardValidators {
         @Override
         public ValidationResult validate(final String subject, final String 
value, final ValidationContext context) {
             return new ValidationResult.Builder().subject(subject).input(value)
-                    .valid(value != null && !value.trim().isEmpty())
+                    .valid(value != null && !value.isBlank())
                     .explanation(subject
                             + " must contain at least one character that is 
not white space").build();
         }
@@ -426,7 +426,7 @@ public class StandardValidators {
         }
 
         Optional<ValidationResult> invalidUri = Arrays.stream(input.split(","))
-                .filter(uri -> uri != null && !uri.trim().isEmpty())
+                .filter(uri -> uri != null && !uri.isBlank())
                 .map(String::trim)
                 .map((uri) -> URI_VALIDATOR.validate(subject, uri, 
context)).filter((uri) -> !uri.isValid()).findFirst();
 
@@ -939,7 +939,7 @@ public class StandardValidators {
                             .explanation("Not a valid Expression Language 
value: " + e.getMessage()).build();
                 }
 
-                if (substituted.trim().isEmpty() && !value.trim().isEmpty()) {
+                if (substituted.isBlank() && !value.isBlank()) {
                     // User specified an Expression and nothing more... assume 
valid.
                     return new 
ValidationResult.Builder().subject(subject).input(value).valid(true).build();
                 }
diff --git a/src/main/java/org/apache/nifi/registry/VariableDescriptor.java 
b/src/main/java/org/apache/nifi/registry/VariableDescriptor.java
index f9e9ce2..02df1cb 100644
--- a/src/main/java/org/apache/nifi/registry/VariableDescriptor.java
+++ b/src/main/java/org/apache/nifi/registry/VariableDescriptor.java
@@ -116,7 +116,7 @@ public final class VariableDescriptor implements 
Comparable<VariableDescriptor>
          * @param name of the property
          */
         public Builder(final String name) {
-            if (null == name || name.trim().isEmpty()) {
+            if (null == name || name.isBlank()) {
                 throw new IllegalArgumentException("Name must not be null or 
empty");
             }
             this.name = name.trim();
diff --git a/src/main/java/org/apache/nifi/time/DurationFormat.java 
b/src/main/java/org/apache/nifi/time/DurationFormat.java
index 6de336a..5c7cb33 100644
--- a/src/main/java/org/apache/nifi/time/DurationFormat.java
+++ b/src/main/java/org/apache/nifi/time/DurationFormat.java
@@ -140,7 +140,7 @@ public class DurationFormat {
         // If the value is already a whole number, return it and the current 
time unit
         if (decimal == Math.rint(decimal)) {
             final long rounded = Math.round(decimal);
-            return Arrays.asList(new Object[]{rounded, timeUnit});
+            return Arrays.asList(rounded, timeUnit);
         } else if (TimeUnit.NANOSECONDS == timeUnit) {
             // The time unit is as small as possible
             if (decimal < 1.0) {
@@ -148,7 +148,7 @@ public class DurationFormat {
             } else {
                 decimal = Math.rint(decimal);
             }
-            return Arrays.asList(new Object[]{(long) decimal, timeUnit});
+            return Arrays.asList((long) decimal, timeUnit);
         } else {
             // Determine the next time unit and the respective multiplier
             TimeUnit smallerTimeUnit = getSmallerTimeUnit(timeUnit);

Reply via email to