Skip to content
Merged
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
86 changes: 86 additions & 0 deletions pmd-ruleset.xml
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public <E extends Enum<E>> Builder allowableValues(final Class<E> enumClass) {
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +53,7 @@ public ResourceReferences createResourceReferences(final String value, final Res
return new StandardResourceReferences(references);
}

@Override
public ResourceReference createResourceReference(final String value, final ResourceDefinition resourceDefinition) {
if (value == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ private void writeUseCase(final UseCase useCase) throws IOException {
writeEndElement();
}

@Override
protected void writeMultiProcessorUseCases(final List<MultiProcessorUseCase> multiProcessorUseCases) throws IOException {
if (multiProcessorUseCases.isEmpty()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/nifi/flowfile/FlowFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ public static String validateKey(final String key) {
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@
* Process Sessions
*/
public class TerminatedTaskException extends ProcessException {
public TerminatedTaskException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public ValidationResult validate(String subject, String input, ValidationContext
@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();
}
Expand Down Expand Up @@ -426,7 +426,7 @@ public ValidationResult validate(final String subject, final String input, final
}

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();

Expand Down Expand Up @@ -939,7 +939,7 @@ public ValidationResult validate(final String subject, final String value, final
.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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static final class Builder {
* @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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/nifi/time/DurationFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ static List<Object> makeWholeNumberTime(double decimal, TimeUnit timeUnit) {
// 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) {
decimal = 1;
} 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);
Expand Down