├── .editorconfig
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── integration-test
├── pom.xml
├── projects
│ ├── pmd-avoid-duplicate-literals
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── AvoidDuplicateLiterals.java
│ ├── pmd-extensions
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── pmd
│ │ │ ├── Bar.java
│ │ │ ├── Errors.java
│ │ │ └── Foo.java
│ └── pmd-junit-rules
│ │ ├── pom.xml
│ │ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── ProductionCode.java
│ │ └── test
│ │ └── java
│ │ └── ProductionCodeTest.java
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── sonar
│ │ │ └── examples
│ │ │ └── pmd
│ │ │ ├── MaximumMethodsCountCheck.java
│ │ │ ├── PmdExtensionPlugin.java
│ │ │ └── PmdExtensionRepository.java
│ └── resources
│ │ └── org
│ │ └── sonar
│ │ └── examples
│ │ └── pmd
│ │ ├── extensions.xml
│ │ └── rulesets.xml
│ └── test
│ ├── java
│ └── com
│ │ └── sonar
│ │ └── it
│ │ └── java
│ │ └── suite
│ │ ├── PmdIT.java
│ │ ├── TestUtils.java
│ │ └── orchestrator
│ │ └── PmdTestOrchestrator.java
│ └── resources
│ ├── TestUtils.txt
│ └── com
│ └── sonar
│ └── it
│ └── java
│ └── PmdTest
│ ├── pmd-all-rules.xml
│ ├── pmd-backup.xml
│ ├── pmd-extensions-profile.xml
│ └── pmd-junit-rules.xml
├── pom.xml
├── sonar-pmd-plugin
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── sonar
│ │ │ └── plugins
│ │ │ └── pmd
│ │ │ ├── PmdConfiguration.java
│ │ │ ├── PmdConstants.java
│ │ │ ├── PmdExecutor.java
│ │ │ ├── PmdLevelUtils.java
│ │ │ ├── PmdPlugin.java
│ │ │ ├── PmdSensor.java
│ │ │ ├── PmdTemplate.java
│ │ │ ├── PmdViolationRecorder.java
│ │ │ ├── TextRangeCalculator.java
│ │ │ ├── profile
│ │ │ ├── PmdProfileExporter.java
│ │ │ └── PmdProfileImporter.java
│ │ │ ├── rule
│ │ │ ├── ExternalDescriptionLoader.java
│ │ │ ├── PmdRulesDefinition.java
│ │ │ └── PmdUnitTestsRulesDefinition.java
│ │ │ └── xml
│ │ │ ├── PmdProperty.java
│ │ │ ├── PmdRule.java
│ │ │ ├── PmdRuleSet.java
│ │ │ ├── PmdRuleSets.java
│ │ │ └── factory
│ │ │ ├── ActiveRulesRuleSetFactory.java
│ │ │ ├── RuleSetFactory.java
│ │ │ ├── RulesProfileRuleSetFactory.java
│ │ │ └── XmlRuleSetFactory.java
│ └── resources
│ │ ├── com
│ │ └── sonar
│ │ │ └── sqale
│ │ │ └── pmd-model.xml
│ │ └── org
│ │ └── sonar
│ │ ├── l10n
│ │ ├── pmd.properties
│ │ └── pmd
│ │ │ └── rules
│ │ │ ├── pmd-p3c
│ │ │ ├── AbstractClassShouldStartWithAbstractNamingRule.html
│ │ │ ├── AbstractMethodOrInterfaceMethodMustUseJavadocRule.html
│ │ │ ├── ArrayNamingShouldHaveBracketRule.html
│ │ │ ├── AvoidApacheBeanUtilsCopyRule.html
│ │ │ ├── AvoidCallStaticSimpleDateFormatRule.html
│ │ │ ├── AvoidCommentBehindStatementRule.html
│ │ │ ├── AvoidComplexConditionRule.html
│ │ │ ├── AvoidConcurrentCompetitionRandomRule.html
│ │ │ ├── AvoidDoubleOrFloatEqualCompareRule.html
│ │ │ ├── AvoidManuallyCreateThreadRule.html
│ │ │ ├── AvoidMissUseOfMathRandomRule.html
│ │ │ ├── AvoidNegationOperatorRule.html
│ │ │ ├── AvoidNewDateGetTimeRule.html
│ │ │ ├── AvoidPatternCompileInMethodRule.html
│ │ │ ├── AvoidReturnInFinallyRule.html
│ │ │ ├── AvoidStartWithDollarAndUnderLineNamingRule.html
│ │ │ ├── AvoidUseTimerRule.html
│ │ │ ├── BigDecimalAvoidDoubleConstructorRule.html
│ │ │ ├── BooleanPropertyShouldNotStartWithIsRule.html
│ │ │ ├── ClassCastExceptionWithSubListToArrayListRule.html
│ │ │ ├── ClassCastExceptionWithToArrayRule.html
│ │ │ ├── ClassMustHaveAuthorRule.html
│ │ │ ├── ClassNamingShouldBeCamelRule.html
│ │ │ ├── CollectionInitShouldAssignCapacityRule.html
│ │ │ ├── CommentsMustBeJavadocFormatRule.html
│ │ │ ├── ConcurrentExceptionWithModifyOriginSubListRule.html
│ │ │ ├── ConstantFieldShouldBeUpperCaseRule.html
│ │ │ ├── CountDownShouldInFinallyRule.html
│ │ │ ├── DontModifyInForeachCircleRule.html
│ │ │ ├── EnumConstantsMustHaveCommentRule.html
│ │ │ ├── EqualsAvoidNullRule.html
│ │ │ ├── ExceptionClassShouldEndWithExceptionRule.html
│ │ │ ├── IbatisMethodQueryForListRule.html
│ │ │ ├── LockShouldWithTryFinallyRule.html
│ │ │ ├── LowerCamelCaseVariableNamingRule.html
│ │ │ ├── MethodReturnWrapperTypeRule.html
│ │ │ ├── MethodTooLongRule.html
│ │ │ ├── NeedBraceRule.html
│ │ │ ├── PackageNamingRule.html
│ │ │ ├── PojoMustOverrideToStringRule.html
│ │ │ ├── PojoMustUsePrimitiveFieldRule.html
│ │ │ ├── PojoNoDefaultValueRule.html
│ │ │ ├── RemoveCommentedCodeRule.html
│ │ │ ├── ServiceOrDaoClassShouldEndWithImplRule.html
│ │ │ ├── StringConcatRule.html
│ │ │ ├── SwitchStatementRule.html
│ │ │ ├── TestClassShouldEndWithTestNamingRule.html
│ │ │ ├── ThreadLocalShouldRemoveRule.html
│ │ │ ├── ThreadPoolCreationRule.html
│ │ │ ├── ThreadShouldSetNameRule.html
│ │ │ ├── TransactionMustHaveRollbackRule.html
│ │ │ ├── UndefineMagicConstantRule.html
│ │ │ ├── UnsupportedExceptionWithModifyAsListRule.html
│ │ │ ├── UpperEllRule.html
│ │ │ ├── UseRightCaseForDateFormatRule.html
│ │ │ └── WrapperTypeEqualityRule.html
│ │ │ ├── pmd-unit-tests
│ │ │ ├── JUnit4SuitesShouldUseSuiteAnnotation.html
│ │ │ ├── JUnit4TestShouldUseAfterAnnotation.html
│ │ │ ├── JUnit4TestShouldUseBeforeAnnotation.html
│ │ │ ├── JUnit4TestShouldUseTestAnnotation.html
│ │ │ ├── JUnitAssertionsShouldIncludeMessage.html
│ │ │ ├── JUnitSpelling.html
│ │ │ ├── JUnitStaticSuite.html
│ │ │ ├── JUnitTestContainsTooManyAsserts.html
│ │ │ ├── JUnitTestsShouldIncludeAssert.html
│ │ │ ├── JUnitUseExpected.html
│ │ │ ├── SimplifyBooleanAssertion.html
│ │ │ ├── TestClassWithoutTestCases.html
│ │ │ ├── UnnecessaryBooleanAssertion.html
│ │ │ ├── UseAssertEqualsInsteadOfAssertTrue.html
│ │ │ ├── UseAssertNullInsteadOfAssertTrue.html
│ │ │ ├── UseAssertSameInsteadOfAssertTrue.html
│ │ │ └── UseAssertTrueInsteadOfAssertEquals.html
│ │ │ └── pmd
│ │ │ ├── AbstractClassWithoutAbstractMethod.html
│ │ │ ├── AbstractClassWithoutAnyMethod.html
│ │ │ ├── AbstractNaming.html
│ │ │ ├── AccessorClassGeneration.html
│ │ │ ├── AddEmptyString.html
│ │ │ ├── AppendCharacterWithChar.html
│ │ │ ├── ArrayIsStoredDirectly.html
│ │ │ ├── AssignmentInOperand.html
│ │ │ ├── AssignmentToNonFinalStatic.html
│ │ │ ├── AtLeastOneConstructor.html
│ │ │ ├── AvoidAccessibilityAlteration.html
│ │ │ ├── AvoidArrayLoops.html
│ │ │ ├── AvoidAssertAsIdentifier.html
│ │ │ ├── AvoidBranchingStatementAsLastInLoop.html
│ │ │ ├── AvoidCallingFinalize.html
│ │ │ ├── AvoidCatchingGenericException.html
│ │ │ ├── AvoidCatchingNPE.html
│ │ │ ├── AvoidCatchingThrowable.html
│ │ │ ├── AvoidConstantsInterface.html
│ │ │ ├── AvoidDecimalLiteralsInBigDecimalConstructor.html
│ │ │ ├── AvoidDeeplyNestedIfStmts.html
│ │ │ ├── AvoidDollarSigns.html
│ │ │ ├── AvoidDuplicateLiterals.html
│ │ │ ├── AvoidEnumAsIdentifier.html
│ │ │ ├── AvoidFieldNameMatchingMethodName.html
│ │ │ ├── AvoidFieldNameMatchingTypeName.html
│ │ │ ├── AvoidFinalLocalVariable.html
│ │ │ ├── AvoidInstanceofChecksInCatchClause.html
│ │ │ ├── AvoidInstantiatingObjectsInLoops.html
│ │ │ ├── AvoidLiteralsInIfCondition.html
│ │ │ ├── AvoidLosingExceptionInformation.html
│ │ │ ├── AvoidMultipleUnaryOperators.html
│ │ │ ├── AvoidPrefixingMethodParameters.html
│ │ │ ├── AvoidPrintStackTrace.html
│ │ │ ├── AvoidProtectedFieldInFinalClass.html
│ │ │ ├── AvoidProtectedMethodInFinalClassNotExtending.html
│ │ │ ├── AvoidReassigningParameters.html
│ │ │ ├── AvoidRethrowingException.html
│ │ │ ├── AvoidStringBufferField.html
│ │ │ ├── AvoidSynchronizedAtMethodLevel.html
│ │ │ ├── AvoidThreadGroup.html
│ │ │ ├── AvoidThrowingNewInstanceOfSameException.html
│ │ │ ├── AvoidThrowingNullPointerException.html
│ │ │ ├── AvoidThrowingRawExceptionTypes.html
│ │ │ ├── AvoidUsingHardCodedIP.html
│ │ │ ├── AvoidUsingNativeCode.html
│ │ │ ├── AvoidUsingOctalValues.html
│ │ │ ├── AvoidUsingShortType.html
│ │ │ ├── AvoidUsingVolatile.html
│ │ │ ├── BadComparison.html
│ │ │ ├── BeanMembersShouldSerialize.html
│ │ │ ├── BigIntegerInstantiation.html
│ │ │ ├── BooleanGetMethodName.html
│ │ │ ├── BooleanInstantiation.html
│ │ │ ├── BrokenNullCheck.html
│ │ │ ├── ByteInstantiation.html
│ │ │ ├── CallSuperFirst.html
│ │ │ ├── CallSuperInConstructor.html
│ │ │ ├── CallSuperLast.html
│ │ │ ├── CheckResultSet.html
│ │ │ ├── CheckSkipResult.html
│ │ │ ├── ClassCastExceptionWithToArray.html
│ │ │ ├── ClassNamingConventions.html
│ │ │ ├── ClassWithOnlyPrivateConstructorsShouldBeFinal.html
│ │ │ ├── CloneMethodMustBePublic.html
│ │ │ ├── CloneMethodMustImplementCloneable.html
│ │ │ ├── CloneMethodMustImplementCloneableWithTypeResolution.html
│ │ │ ├── CloneMethodReturnTypeMustMatchClassName.html
│ │ │ ├── CloneThrowsCloneNotSupportedException.html
│ │ │ ├── CloseResource.html
│ │ │ ├── CollapsibleIfStatements.html
│ │ │ ├── CommentContent.html
│ │ │ ├── CommentDefaultAccessModifier.html
│ │ │ ├── CommentRequired.html
│ │ │ ├── CommentSize.html
│ │ │ ├── CompareObjectsWithEquals.html
│ │ │ ├── ConfusingTernary.html
│ │ │ ├── ConsecutiveAppendsShouldReuse.html
│ │ │ ├── ConsecutiveLiteralAppends.html
│ │ │ ├── ConstructorCallsOverridableMethod.html
│ │ │ ├── CouplingBetweenObjects.html
│ │ │ ├── CyclomaticComplexity.html
│ │ │ ├── DataflowAnomalyAnalysis.html
│ │ │ ├── DefaultLabelNotLastInSwitchStmt.html
│ │ │ ├── DefaultPackage.html
│ │ │ ├── DoNotCallGarbageCollectionExplicitly.html
│ │ │ ├── DoNotCallSystemExit.html
│ │ │ ├── DoNotExtendJavaLangError.html
│ │ │ ├── DoNotHardCodeSDCard.html
│ │ │ ├── DoNotThrowExceptionInFinally.html
│ │ │ ├── DoNotUseThreads.html
│ │ │ ├── DontCallThreadRun.html
│ │ │ ├── DontImportJavaLang.html
│ │ │ ├── DontImportSun.html
│ │ │ ├── DontUseFloatTypeForLoopIndices.html
│ │ │ ├── DoubleCheckedLocking.html
│ │ │ ├── DuplicateImports.html
│ │ │ ├── EmptyCatchBlock.html
│ │ │ ├── EmptyFinalizer.html
│ │ │ ├── EmptyFinallyBlock.html
│ │ │ ├── EmptyIfStmt.html
│ │ │ ├── EmptyInitializer.html
│ │ │ ├── EmptyMethodInAbstractClassShouldBeAbstract.html
│ │ │ ├── EmptyStatementBlock.html
│ │ │ ├── EmptyStatementNotInLoop.html
│ │ │ ├── EmptyStaticInitializer.html
│ │ │ ├── EmptySwitchStatements.html
│ │ │ ├── EmptySynchronizedBlock.html
│ │ │ ├── EmptyTryBlock.html
│ │ │ ├── EmptyWhileStmt.html
│ │ │ ├── EqualsNull.html
│ │ │ ├── ExceptionAsFlowControl.html
│ │ │ ├── ExcessiveClassLength.html
│ │ │ ├── ExcessiveImports.html
│ │ │ ├── ExcessiveMethodLength.html
│ │ │ ├── ExcessiveParameterList.html
│ │ │ ├── ExcessivePublicCount.html
│ │ │ ├── ExtendsObject.html
│ │ │ ├── FieldDeclarationsShouldBeAtStartOfClass.html
│ │ │ ├── FinalFieldCouldBeStatic.html
│ │ │ ├── FinalizeDoesNotCallSuperFinalize.html
│ │ │ ├── FinalizeOnlyCallsSuperFinalize.html
│ │ │ ├── FinalizeOverloaded.html
│ │ │ ├── FinalizeShouldBeProtected.html
│ │ │ ├── ForLoopShouldBeWhileLoop.html
│ │ │ ├── ForLoopsMustUseBraces.html
│ │ │ ├── GenericsNaming.html
│ │ │ ├── GodClass.html
│ │ │ ├── GuardDebugLogging.html
│ │ │ ├── GuardLogStatement.html
│ │ │ ├── GuardLogStatementJavaUtil.html
│ │ │ ├── IdempotentOperations.html
│ │ │ ├── IfElseStmtsMustUseBraces.html
│ │ │ ├── IfStmtsMustUseBraces.html
│ │ │ ├── ImmutableField.html
│ │ │ ├── ImportFromSamePackage.html
│ │ │ ├── InefficientEmptyStringCheck.html
│ │ │ ├── InefficientStringBuffering.html
│ │ │ ├── InstantiationToGetClass.html
│ │ │ ├── InsufficientStringBufferDeclaration.html
│ │ │ ├── IntegerInstantiation.html
│ │ │ ├── JumbledIncrementer.html
│ │ │ ├── LawOfDemeter.html
│ │ │ ├── LocalHomeNamingConvention.html
│ │ │ ├── LocalInterfaceSessionNamingConvention.html
│ │ │ ├── LocalVariableCouldBeFinal.html
│ │ │ ├── LoggerIsNotStaticFinal.html
│ │ │ ├── LogicInversion.html
│ │ │ ├── LongInstantiation.html
│ │ │ ├── LongVariable.html
│ │ │ ├── LooseCoupling.html
│ │ │ ├── LooseCouplingWithTypeResolution.html
│ │ │ ├── LoosePackageCoupling.html
│ │ │ ├── MDBAndSessionBeanNamingConvention.html
│ │ │ ├── MethodArgumentCouldBeFinal.html
│ │ │ ├── MethodNamingConventions.html
│ │ │ ├── MethodReturnsInternalArray.html
│ │ │ ├── MethodWithSameNameAsEnclosingClass.html
│ │ │ ├── MisleadingVariableName.html
│ │ │ ├── MisplacedNullCheck.html
│ │ │ ├── MissingBreakInSwitch.html
│ │ │ ├── MissingSerialVersionUID.html
│ │ │ ├── MissingStaticMethodInNonInstantiatableClass.html
│ │ │ ├── ModifiedCyclomaticComplexity.html
│ │ │ ├── MoreThanOneLogger.html
│ │ │ ├── NPathComplexity.html
│ │ │ ├── NcssConstructorCount.html
│ │ │ ├── NcssMethodCount.html
│ │ │ ├── NcssTypeCount.html
│ │ │ ├── NoPackage.html
│ │ │ ├── NonCaseLabelInSwitchStatement.html
│ │ │ ├── NonStaticInitializer.html
│ │ │ ├── NonThreadSafeSingleton.html
│ │ │ ├── NullAssignment.html
│ │ │ ├── OneDeclarationPerLine.html
│ │ │ ├── OnlyOneReturn.html
│ │ │ ├── OptimizableToArrayCall.html
│ │ │ ├── OverrideBothEqualsAndHashcode.html
│ │ │ ├── PackageCase.html
│ │ │ ├── PositionLiteralsFirstInCaseInsensitiveComparisons.html
│ │ │ ├── PositionLiteralsFirstInComparisons.html
│ │ │ ├── PrematureDeclaration.html
│ │ │ ├── PreserveStackTrace.html
│ │ │ ├── ProperCloneImplementation.html
│ │ │ ├── ProperLogger.html
│ │ │ ├── RedundantFieldInitializer.html
│ │ │ ├── RemoteInterfaceNamingConvention.html
│ │ │ ├── RemoteSessionInterfaceNamingConvention.html
│ │ │ ├── ReplaceEnumerationWithIterator.html
│ │ │ ├── ReplaceHashtableWithMap.html
│ │ │ ├── ReplaceVectorWithList.html
│ │ │ ├── ReturnEmptyArrayRatherThanNull.html
│ │ │ ├── ReturnFromFinallyBlock.html
│ │ │ ├── ShortClassName.html
│ │ │ ├── ShortInstantiation.html
│ │ │ ├── ShortMethodName.html
│ │ │ ├── ShortVariable.html
│ │ │ ├── SignatureDeclareThrowsException.html
│ │ │ ├── SignatureDeclareThrowsExceptionWithTypeResolution.html
│ │ │ ├── SimpleDateFormatNeedsLocale.html
│ │ │ ├── SimplifiedTernary.html
│ │ │ ├── SimplifyBooleanExpressions.html
│ │ │ ├── SimplifyBooleanReturns.html
│ │ │ ├── SimplifyConditional.html
│ │ │ ├── SimplifyStartsWith.html
│ │ │ ├── SingleMethodSingleton.html
│ │ │ ├── SingletonClassReturningNewInstance.html
│ │ │ ├── SingularField.html
│ │ │ ├── StaticEJBFieldShouldBeFinal.html
│ │ │ ├── StdCyclomaticComplexity.html
│ │ │ ├── StringBufferInstantiationWithChar.html
│ │ │ ├── StringInstantiation.html
│ │ │ ├── StringToString.html
│ │ │ ├── SuspiciousConstantFieldName.html
│ │ │ ├── SuspiciousEqualsMethodName.html
│ │ │ ├── SuspiciousHashcodeMethodName.html
│ │ │ ├── SuspiciousOctalEscape.html
│ │ │ ├── SwitchDensity.html
│ │ │ ├── SwitchStmtsShouldHaveDefault.html
│ │ │ ├── SystemPrintln.html
│ │ │ ├── TooFewBranchesForASwitchStatement.html
│ │ │ ├── TooManyFields.html
│ │ │ ├── TooManyMethods.html
│ │ │ ├── TooManyStaticImports.html
│ │ │ ├── UncommentedEmptyConstructor.html
│ │ │ ├── UncommentedEmptyMethodBody.html
│ │ │ ├── UnconditionalIfStatement.html
│ │ │ ├── UnnecessaryCaseChange.html
│ │ │ ├── UnnecessaryConstructor.html
│ │ │ ├── UnnecessaryConversionTemporary.html
│ │ │ ├── UnnecessaryFinalModifier.html
│ │ │ ├── UnnecessaryFullyQualifiedName.html
│ │ │ ├── UnnecessaryLocalBeforeReturn.html
│ │ │ ├── UnnecessaryParentheses.html
│ │ │ ├── UnnecessaryReturn.html
│ │ │ ├── UnnecessaryWrapperObjectCreation.html
│ │ │ ├── UnsynchronizedStaticDateFormatter.html
│ │ │ ├── UnusedFormalParameter.html
│ │ │ ├── UnusedImports.html
│ │ │ ├── UnusedImportsWithTypeResolution.html
│ │ │ ├── UnusedLocalVariable.html
│ │ │ ├── UnusedModifier.html
│ │ │ ├── UnusedNullCheckInEquals.html
│ │ │ ├── UnusedPrivateField.html
│ │ │ ├── UnusedPrivateMethod.html
│ │ │ ├── UseArrayListInsteadOfVector.html
│ │ │ ├── UseArraysAsList.html
│ │ │ ├── UseCollectionIsEmpty.html
│ │ │ ├── UseConcurrentHashMap.html
│ │ │ ├── UseCorrectExceptionLogging.html
│ │ │ ├── UseEqualsToCompareStrings.html
│ │ │ ├── UseIndexOfChar.html
│ │ │ ├── UseLocaleWithCaseConversions.html
│ │ │ ├── UseNotifyAllInsteadOfNotify.html
│ │ │ ├── UseObjectForClearerAPI.html
│ │ │ ├── UseProperClassLoader.html
│ │ │ ├── UseStringBufferForStringAppends.html
│ │ │ ├── UseStringBufferLength.html
│ │ │ ├── UseUtilityClass.html
│ │ │ ├── UseVarargs.html
│ │ │ ├── UselessOperationOnImmutable.html
│ │ │ ├── UselessOverridingMethod.html
│ │ │ ├── UselessParentheses.html
│ │ │ ├── UselessQualifiedThis.html
│ │ │ ├── UselessStringValueOf.html
│ │ │ ├── VariableNamingConventions.html
│ │ │ ├── WhileLoopsMustUseBraces.html
│ │ │ └── XPathRule.html
│ │ └── plugins
│ │ └── pmd
│ │ ├── profile-sonar-way.xml
│ │ ├── rules-p3c.xml
│ │ ├── rules-unit-tests.xml
│ │ └── rules.xml
│ └── test
│ ├── java
│ └── org
│ │ └── sonar
│ │ └── plugins
│ │ └── pmd
│ │ ├── PmdConfigurationTest.java
│ │ ├── PmdConstantsTest.java
│ │ ├── PmdExecutorTest.java
│ │ ├── PmdLevelUtilsTest.java
│ │ ├── PmdPluginTest.java
│ │ ├── PmdRulesDefinitionTest.java
│ │ ├── PmdSensorTest.java
│ │ ├── PmdTemplateTest.java
│ │ ├── PmdTestUtils.java
│ │ ├── PmdUnitTestsRulesDefinitionTest.java
│ │ ├── PmdViolationRecorderTest.java
│ │ ├── TextRangeCalculatorTest.java
│ │ ├── profile
│ │ ├── PmdProfileExporterTest.java
│ │ └── PmdProfileImporterTest.java
│ │ ├── rule
│ │ └── ExternalDescriptionLoaderTest.java
│ │ └── xml
│ │ └── PmdRuleSetsTest.java
│ └── resources
│ └── org
│ └── sonar
│ ├── l10n
│ └── languageKey
│ │ └── rules
│ │ └── repoKey
│ │ └── ruleWithExternalInfo.html
│ └── plugins
│ └── pmd
│ ├── complex-with-unknown-nodes.xml
│ ├── export_rule_with_all_params_empty.xml
│ ├── export_rule_with_empty_param.xml
│ ├── export_simple.xml
│ ├── export_xpath_rules.xml
│ ├── junit.xml
│ ├── simple.xml
│ └── source.txt
└── travis.sh
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [.idea/*.xml]
4 | indent_style = space
5 | indent_size = 2
6 | max_line_length = 0
7 |
8 | [*.{java}]
9 | indent_style = tab
10 | indent_size = 4
11 | end_of_line = lf
12 | charset = utf-8
13 | trim_trailing_whitespace = true
14 | insert_final_newline = true
15 |
16 | [*.{json,js,xml,html,css,scss}]
17 | charset = utf-8
18 | end_of_line = lf
19 | indent_size = 2
20 | indent_style = space
21 | insert_final_newline = true
22 | max_line_length = 120
23 | trim_trailing_whitespace = true
24 |
25 | [*.{yml,properties}]
26 | indent_style = space
27 | indent_size = 2
28 | end_of_line = lf
29 | charset = utf-8
30 | trim_trailing_whitespace = true
31 | insert_final_newline = true
32 |
33 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # ---- Maven
2 | target/
3 |
4 | # ---- IntelliJ IDEA
5 | *.iws
6 | *.iml
7 | *.ipr
8 | .idea/
9 |
10 | # ---- Eclipse
11 | .classpath
12 | .project
13 | .settings
14 |
15 | # ---- Mac OS X
16 | .DS_Store?
17 | Icon?
18 | # Thumbnails
19 | ._*
20 | # Files that might appear on external disk
21 | .Spotlight-V100
22 | .Trashes
23 |
24 | # ---- Windows
25 | # Windows image file caches
26 | Thumbs.db
27 | # Folder config file
28 | Desktop.ini
29 | .java-version
30 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | sudo: false
3 |
4 | addons:
5 | sonarcloud:
6 | organization: "jensgerdes-github"
7 | token:
8 | secure: "U299FqcJAMNfblrZF8R/ivqRk7KNdSOdcyWI4h5dgOLlQHj+HHrF2GJB2fOVeaB53snOkCycM/ZQgqTLlS1PU2NUca3TroNXj6jpNK1Erb/TXqFMKK+rmsN+hcxudDYGnQFIVnWy4lsg72jlK3Qvktt0XyfuYjMqQbsp3zwhlxw="
9 |
10 | jdk:
11 | - openjdk11
12 |
13 | install: true
14 | script: ./travis.sh
15 | env:
16 | - TEST=ci
17 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[6.7] SJ_VERSION=LATEST_RELEASE[5.0]
18 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[6.7] SJ_VERSION=DEV
19 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[7.2] SJ_VERSION=DEV
20 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[7.5] SJ_VERSION=DEV
21 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[7.6] SJ_VERSION=DEV
22 | - TEST=plugin SQ_VERSION=LATEST_RELEASE[7.7] SJ_VERSION=DEV
23 | - TEST=plugin SQ_VERSION=DEV SJ_VERSION=DEV
24 | - TEST=javadoc
25 |
26 | cache:
27 | directories:
28 | - '$HOME/.m2/repository'
29 | - '$HOME/.sonar'
30 | - '$HOME/jvm'
31 | - '$HOME/maven'
32 |
33 | notifications:
34 | email:
35 | - jens@gerdes.digital
36 |
--------------------------------------------------------------------------------
/integration-test/projects/pmd-avoid-duplicate-literals/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | abstract class BaseControllerDemo{ 4 | } 5 | abstract class AbstractActionDemo{ 6 | } 7 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AbstractMethodOrInterfaceMethodMustUseJavadocRule.html: -------------------------------------------------------------------------------- 1 | Abstract methods (including methods in interface) should be commented by Javadoc. Examples: 2 |
3 | /** 4 | * fetch data by rule id 5 | * 6 | * @param ruleId rule id 7 | * @param page page number 8 | * @param jsonContext json format context 9 | * @return Result >XxxxDO< 10 | */ 11 | Result<XxxxDO> fetchDataByRuleId(Long ruleId, Integer page, String jsonContext); 12 |13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ArrayNamingShouldHaveBracketRule.html: -------------------------------------------------------------------------------- 1 | Brackets are a part of an Array type. The definition could be: String[] args. Examples: 2 |
3 | String[] a = new String[3]; 4 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidApacheBeanUtilsCopyRule.html: -------------------------------------------------------------------------------- 1 | Avoid using *Apache Beanutils* to copy attributes. Examples: 2 |
3 | TestObject a = new TestObject(); 4 | TestObject b = new TestObject(); 5 | a.setX(b.getX()); 6 | a.setY(b.getY()); 7 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidCallStaticSimpleDateFormatRule.html: -------------------------------------------------------------------------------- 1 | SimpleDataFormat is unsafe, do not define it as a static variable. If have to, lock or DateUtils class must be used.
5 | Positive example 1: 6 | private static final String FORMAT = "yyyy-MM-dd HH:mm:ss"; 7 | public String getFormat(Date date){ 8 | SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT); 9 | return sdf.format(date); 10 | } 11 | 12 | Positive example 2: 13 | private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 14 | public void getFormat(){ 15 | synchronized (sdf){ 16 | sdf.format(new Date()); 17 | ….; 18 | } 19 | 20 | Positive example 3: 21 | private static final ThreadLocal-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidCommentBehindStatementRule.html: -------------------------------------------------------------------------------- 1 | Single line comments in a method should be put above the code to be commented, by using // and multiple lines by using /* */. 2 | Examples: 3 |DATE_FORMATTER = new ThreadLocal () { 22 | @Override 23 | protected DateFormat initialValue() { 24 | return new SimpleDateFormat("yyyy-MM-dd"); 25 | } 26 | }; 27 |
4 | public void method() { 5 | // Put single line comment above code. (Note: align '//' comment with code) 6 | int a = 3; 7 | 8 | /** 9 | * Some description about follow code. (Note: align '/**' comment with code) 10 | */ 11 | int b = 4; 12 | } 13 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidComplexConditionRule.html: -------------------------------------------------------------------------------- 1 | Do not use complicated statements in conditional statements (except for frequently used methods like getXxx/isXxx). Use boolean variables to store results of complicated statements temporarily will increase the code's readability. 2 |
Examples:
3 |4 | Negative example: 5 | if ((file.open(fileName, "w") != null) && (...) || (...)) { 6 | // ... 7 | } 8 | 9 | Positive example: 10 | boolean existed = (file.open(fileName, "w") != null) && (...) || (...); 11 | if (existed) { 12 | //... 13 | } 14 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidConcurrentCompetitionRandomRule.html: -------------------------------------------------------------------------------- 1 | Avoid using Random instance by multiple threads. Although it is safe to share this instance, competition on the same seed will damage performance. Note: Random instance includes instances of java.util.Random and Math.random(). 2 | Examples: 3 |
4 | Positive example 1: 5 | /** 6 | * @author caikang 7 | * @date 2017/04/07 8 | */ 9 | public class RandomInThread extends Thread { 10 | private Random random = new Random(); 11 | @Override 12 | public void run() { 13 | long t = random.nextLong(); 14 | } 15 | } 16 | Positive example 2: 17 | /** 18 | * @author caikang 19 | * @date 2017/04/07 20 | */ 21 | public class RandomInThread extends Thread { 22 | private Random random = ThreadLocalRandom.current(); 23 | @Override 24 | public void run() { 25 | long t = random.nextLong(); 26 | } 27 | } 28 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidDoubleOrFloatEqualCompareRule.html: -------------------------------------------------------------------------------- 1 |
浮点数之间的等值判断,基本数据类型不能用==来比较,包装数据类型不能用equals来判断
2 |3 | 浮点数采用“尾数+阶码”的编码方式,类似于科学计数法的“有效数字+指数”的表示方式。二进制无法精确表示大部分的十进制小数,具体原理参考《码出高效》 4 | 改进方式: 5 | 1)指定一个误差范围,两个浮点数的差值在此范围之内,则认为是相等的 6 | float a = 1.0f - 0.9f; 7 | float b = 0.9f - 0.8f; 8 | float diff = 1e-6f; 9 | 10 | if (Math.abs(a - b) < diff) { 11 | System.out.println("true"); 12 | } 13 | 2) 使用BigDecimal来定义值,再进行浮点数的运算操作 14 | BigDecimal a = new BigDecimal("1.0"); 15 | BigDecimal b = new BigDecimal("0.9"); 16 | BigDecimal c = new BigDecimal("0.8"); 17 | 18 | BigDecimal x = a.subtract(b); 19 | BigDecimal y = b.subtract(c); 20 | 21 | if (x.equals(y)) { 22 | System.out.println("true"); 23 | } 24 |25 |
26 | Negative example: 27 | float g = 0.7f-0.6f; 28 | float h = 0.8f-0.7f; 29 | if (g == h) { 30 | System.out.println("true"); 31 |32 |
33 | Positive example: 34 | double dis = 1e-6; 35 | double d1 = 0.0000001d; 36 | double d2 = 0d; 37 | System.out.println(Math.abs(d1 - d2) < dis); 38 |39 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidManuallyCreateThreadRule.html: -------------------------------------------------------------------------------- 1 | Threads should be provided by thread pools. Explicitly creating threads is not allowed. Examples: 2 |
3 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() 4 | .setNameFormat("demo-pool-%d").build(); 5 | ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1, 6 | 0L, TimeUnit.MILLISECONDS, 7 | new LinkedBlockingQueue-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidMissUseOfMathRandomRule.html: -------------------------------------------------------------------------------- 1 | The return type of Math.random() is double, value range is 0>=x>1 (0 is possible). If a random integer is required, do not multiply x by 10 then round the result. The correct way is to use nextInt or nextLong method which belong to Random Object. 2 | Examples: 3 |(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); 8 | 9 | singleThreadPool.execute(()-> System.out.println(Thread.currentThread().getName())); 10 | singleThreadPool.shutdown(); 11 |
4 | Negative example: 5 | Long randomLong =(long) (Math.random() * 10); 6 | Positive example: 7 | Long randomLong = new Random().nextLong(); 8 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidNegationOperatorRule.html: -------------------------------------------------------------------------------- 1 | Avoid using the negation operator '!'. 2 |
Examples:
3 |4 | Negative example: 5 | // Use `if (!(x >= 628))` to represent that x is less than 628. 6 | if (!(x >= 628)) { 7 | // ... 8 | } 9 | 10 | Positive example: 11 | // Use `if (x < 628)` to represent that x is less than 628. 12 | if (x < 628)) { 13 | // ... 14 | } 15 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidNewDateGetTimeRule.html: -------------------------------------------------------------------------------- 1 | Use System.currentTimeMillis() to get the current millisecond. Do not use new Date().getTime().
5 | public class TimeMillisDemo { 6 | public static void main(String args[]) { 7 | // Positive example: 8 | long a = System.currentTimeMillis(); 9 | // Negative example: 10 | long b = new Date().getTime(); 11 | 12 | System.out.println(a); 13 | System.out.println(b); 14 | } 15 | } 16 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidPatternCompileInMethodRule.html: -------------------------------------------------------------------------------- 1 | When using regex, precompile needs to be done in order to increase the matching performance. Examples: 2 |
3 | public class XxxClass { 4 | // Use precompile 5 | private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]+"); 6 | public Pattern getNumberPattern() { 7 | // Avoid use Pattern.compile in method body. 8 | Pattern localPattern = Pattern.compile("[0-9]+"); 9 | return localPattern; 10 | } 11 | } 12 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidReturnInFinallyRule.html: -------------------------------------------------------------------------------- 1 | Never use return within a finally block. A return statement in a finally block will cause exceptions or result in a discarded return value in the try-catch block. Examples: 2 |
3 | Negative example: 4 | public static Long readFileLength(String fileName) { 5 | try { 6 | File file = new File(fileName); 7 | RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); 8 | return randomAccessFile.length(); 9 | } catch (Exception e) { 10 | logger.error(e.getMessage(), e); 11 | } finally { 12 | countDownLatch.countDown(); 13 | return 0L; 14 | } 15 | } 16 |17 | 18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidStartWithDollarAndUnderLineNamingRule.html: -------------------------------------------------------------------------------- 1 | All names should not start or end with an underline or a dollar sign. 2 | Examples: 3 |
4 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/AvoidUseTimerRule.html: -------------------------------------------------------------------------------- 1 | Run multiple TimeTask by using ScheduledExecutorService rather than Timer because Timer will kill all running threads in case of failing to catch exceptions. 2 |
Examples:
3 |4 | //org.apache.commons.lang3.concurrent.BasicThreadFactory 5 | ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, 6 | new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build()); 7 | executorService.scheduleAtFixedRate(new Runnable() { 8 | @Override 9 | public void run() { 10 | //do something 11 | } 12 | },initialDelay,period, TimeUnit.HOURS); 13 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/BigDecimalAvoidDoubleConstructorRule.html: -------------------------------------------------------------------------------- 1 |
说明:BigDecimal(double)存在精度损失风险,在精确计算或值比较的场景中可能会导致业务逻辑异常。
2 | Negative example: 3 |4 | BigDecimal good1 = new BigDecimal(0.1); 5 |6 | Positive example: 7 |
8 | BigDecimal good1 = new BigDecimal("0.1"); 9 | BigDecimal good2 = BigDecimal.valueOf(0.1); 10 |11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/BooleanPropertyShouldNotStartWithIsRule.html: -------------------------------------------------------------------------------- 1 | Do not add 'is' as prefix while defining Boolean variable, since it may cause a serialization exception in some Java Frameworks 2 |
Examples:
3 |4 | public class DemoDO{ 5 | Boolean success; 6 | Boolean delete; 7 | } 8 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithSubListToArrayListRule.html: -------------------------------------------------------------------------------- 1 | Do not cast subList in class ArrayList, otherwise ClassCastException will be thrown. 2 |
Examples:
3 |4 | Negative example: 5 | List-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithToArrayRule.html: -------------------------------------------------------------------------------- 1 | Do not use toArray method without arguments. Since the return type is Object[], ClassCastException will be thrown when casting it to a different array type. 2 |list = new ArrayList (); 6 | list.add("22"); 7 | //warn 8 | List test = (ArrayList ) list.subList(0, 1); 9 | 10 | Positive example: 11 | List list2 = new ArrayList (list.subList(0, 1)); 12 |
Examples:
3 |4 | Negative example: 5 | Integer[] a = (Integer [])c.toArray(); 6 | 7 | Positive example: 8 | Integer[] b = (Integer [])c.toArray(new Integer[c.size()]); 9 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassMustHaveAuthorRule.html: -------------------------------------------------------------------------------- 1 | Every class should include information of author(s) and date.
Examples:
5 |6 | /** 7 | * Demo class 8 | * 9 | * @author keriezhang 10 | * @date 2016/10/31 11 | */ 12 | public class CodeNoteDemo { 13 | } 14 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassNamingShouldBeCamelRule.html: -------------------------------------------------------------------------------- 1 | Class names should be nouns in UpperCamelCase except domain models: DO, BO, DTO, VO, etc. 2 |
Examples:
3 |4 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CollectionInitShouldAssignCapacityRule.html: -------------------------------------------------------------------------------- 1 | Set a size when initializing a collection if possible. 2 |
Examples:
3 |4 | Negative example: 5 | Map-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CommentsMustBeJavadocFormatRule.html: -------------------------------------------------------------------------------- 1 | Javadoc should be used for classes, class variables and methods. The format should be '/** comment **/', rather than '// xxx'. 2 |map = new HashMap (); 6 | 7 | Positive example: 8 | Map map = new HashMap (16); 9 |
Examples:
3 |4 | /** 5 | * 6 | * XXX class function description. 7 | * 8 | */ 9 | public class XxClass implements Serializable { 10 | private static final long serialVersionUID = 113323427779853001L; 11 | /** 12 | * id 13 | */ 14 | private Long id; 15 | /** 16 | * title 17 | */ 18 | private String title; 19 | /** 20 | * find by id 21 | * 22 | * @param ruleId rule id 23 | * @param page start from 1 24 | * @return Result-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConcurrentExceptionWithModifyOriginSubListRule.html: -------------------------------------------------------------------------------- 1 | When using subList, be careful to modify the size of original list. It might cause ConcurrentModificationException when performing traversing, adding or deleting on the subList. 2 |25 | */ 26 | public Result funcA(Long ruleId, Integer page) { 27 | return null; 28 | } 29 | } 30 |
Examples:
3 |4 | Negative example: 5 | List-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConstantFieldShouldBeUpperCaseRule.html: -------------------------------------------------------------------------------- 1 | Constant variable names should be written in upper characters separated by underscores. These names should be semantically complete and clear 2 |originList = new ArrayList (); 6 | originList.add("22"); 7 | List subList = originList.subList(0, 1); 8 | //warn 9 | originList.add("22"); 10 |
Examples:
3 |4 | public class ConstantNameDemo { 5 | /** 6 | * max stock count 7 | */ 8 | public static final Long MAX_STOCK_COUNT = 50000L; 9 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CountDownShouldInFinallyRule.html: -------------------------------------------------------------------------------- 1 | When using CountDownLatch to convert asynchronous operations to synchronous ones,each thread must call countdown method before quitting. Make sure to catch any exception during thread running, to let countdown method be executed. If main thread cannot reach await method, program will return until timeout. 2 |
Examples:
3 |4 | /** 5 | * @author caikang 6 | * @date 2017/04/07 7 | */ 8 | public class CountDownExample { 9 | public void operate(CountDownLatch countDownLatch){ 10 | try{ 11 | System.out.println("business logic"); 12 | }catch (RuntimeException e){ 13 | // do something 14 | }finally { 15 | countDownLatch.countDown(); 16 | } 17 | } 18 | } 19 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/DontModifyInForeachCircleRule.html: -------------------------------------------------------------------------------- 1 | Do not remove or add elements to a collection in a foreach loop. Please use Iterator to remove an item. Iterator object should be synchronized when executing concurrent operations. 2 |
Examples:
3 |4 | Negative example: 5 | List-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/EnumConstantsMustHaveCommentRule.html: -------------------------------------------------------------------------------- 1 | All enumeration type fields should be commented as Javadoc style. 2 |originList = new ArrayList (); 6 | originList.add("22"); 7 | for (String item : originList) { 8 | //warn 9 | list.add("bb"); 10 | } 11 | 12 | Positive example: 13 | Iterator it=b.iterator(); 14 | while(it.hasNext()){ 15 | Integer temp = it.next(); 16 | if (delCondition) { 17 | it.remove(); 18 | } 19 | } 20 |
Examples:
3 |4 | public enum TestEnum { 5 | /** 6 | * agree 7 | */ 8 | agree("agree"), 9 | /** 10 | * reject 11 | */ 12 | reject("reject"); 13 | 14 | private String action; 15 | 16 | TestEnum(String action) { 17 | this.action = action; 18 | } 19 | 20 | public String getAction() { 21 | return action; 22 | } 23 | } 24 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/EqualsAvoidNullRule.html: -------------------------------------------------------------------------------- 1 | Since NullPointerException can possibly be thrown while calling the equals method of Object, equals should be invoked by a constant or an object that is definitely not null. 2 |
Examples:
3 |4 | public void f(String str){ 5 | String inner = "hi"; 6 | if (inner.equals(str)) { 7 | System.out.println("hello world"); 8 | } 9 | } 10 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ExceptionClassShouldEndWithExceptionRule.html: -------------------------------------------------------------------------------- 1 | Exception class names must be ended with Exception 2 |
Examples:
3 |4 | public class CacheDemoException extends Exception{ 5 | } 6 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/IbatisMethodQueryForListRule.html: -------------------------------------------------------------------------------- 1 | iBatis built in queryForList(String statementName, int start, int size) is not recommended. -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/LockShouldWithTryFinallyRule.html: -------------------------------------------------------------------------------- 1 |
2 | 在使用阻塞等待获取锁的方式中,必须在try代码块之外,并且在加锁方法与try代码块之间没有任何可能抛出异常的方法调用,避免加锁成功后,在finally中无法解锁。 3 | 说明一:如果在lock方法与try代码块之间的方法调用抛出异常,那么无法解锁,造成其它线程无法成功获取锁。 4 | 说明二:如果lock方法在try代码块之内,可能由于其它方法抛出异常,导致在finally代码块中,unlock对未加锁的对象解锁,它会调用AQS的tryRelease方法(取决于具体实现类),抛出IllegalMonitorStateException异常。 5 | 说明三:在Lock对象的lock方法实现中可能抛出unchecked异常,产生的后果与说明二相同。 6 |
7 | example: 8 |9 | Positive example: 10 | Lock lock = new XxxLock(); 11 | // ... 12 | lock.lock(); 13 | try { 14 | doSomething(); 15 | doOthers(); 16 | } finally { 17 | lock.unlock(); 18 | } 19 | 20 | Negative example: 21 | Lock lock = new XxxLock(); 22 | // ... 23 | try { 24 | // If an exception is thrown here, the finally block is executed directly 25 | doSomething(); 26 | // The finally block executes regardless of whether the lock is successful or not 27 | lock.lock(); 28 | doOthers(); 29 | 30 | } finally { 31 | lock.unlock(); 32 | } 33 | 34 |35 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/LowerCamelCaseVariableNamingRule.html: -------------------------------------------------------------------------------- 1 | Method names, parameter names, member variable names, and local variable names should be written in lowerCamelCase 2 |
Examples:
3 |4 | 5 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/MethodReturnWrapperTypeRule.html: -------------------------------------------------------------------------------- 1 | If the return type is primitive, return a value of wrapper class may cause NullPointerException. 2 |
Examples:
3 |4 | public int method() { 5 | Integer a = null; 6 | return a; 7 | } 8 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/MethodTooLongRule.html: -------------------------------------------------------------------------------- 1 | The total number of lines, including the method signature, closing brace, codes, comments, blank lines, line breaks and any invisible lines, should not be more than 80. -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/NeedBraceRule.html: -------------------------------------------------------------------------------- 1 | Braces are used with if, else, for, do and while statements, even if the body contains only a single statement. Avoid using the following example: if (condition) statements; 2 |
Examples:
3 |4 | if (flag) { 5 | System.out.println("hello world"); 6 | } 7 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/PackageNamingRule.html: -------------------------------------------------------------------------------- 1 | All Service and DAO classes must be interface based on SOA principle. Implementation class names. 2 |
Examples:
3 |4 | com.alibaba.mpp.util / com.taobao.tddl.domain.dto 5 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/PojoMustOverrideToStringRule.html: -------------------------------------------------------------------------------- 1 | The toString method must be implemented in a POJO class. The super.toString method should be called in front of the whole implementation if the current class extends another POJO class. 2 |
Examples:
3 |4 | public class ToStringDemo extends Super{ 5 | private String secondName; 6 | @Override 7 | public String toString() { 8 | return super.toString() + "ToStringDemo{" + "secondName='" + secondName + '\'' + '}'; 9 | } 10 | } 11 | class Super { 12 | private String firstName; 13 | @Override 14 | public String toString() { 15 | return "Super{" + "firstName=" + firstName + '\'' + '}'; 16 | } 17 | } 18 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/PojoMustUsePrimitiveFieldRule.html: -------------------------------------------------------------------------------- 1 |
2 | Rules for using primitive data types and wrapper classes: 3 | 1) Members of a POJO class must be wrapper classes. 4 | 2) The return value and arguments of a RPC method must be wrapper classes. 5 | 3) [Recommended] Local variables should be primitive data types. 6 |
7 |
Examples:
8 |9 | public class DemoDO { 10 | String str; 11 | Integer a; 12 | } 13 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/PojoNoDefaultValueRule.html: -------------------------------------------------------------------------------- 1 | While defining POJO classes like DO, DTO, VO, etc., do not assign any default values to the members. 2 |
Examples:
3 |4 | public class DemoDO { 5 | String str; 6 | Integer a; 7 | } 8 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/RemoveCommentedCodeRule.html: -------------------------------------------------------------------------------- 1 | Codes or configuration that is noticed to be obsoleted should be resolutely removed from projects. 2 |
Examples:
3 |4 | public static void hello() { 5 | /// Business is stopped temporarily by the owner. 6 | // Business business = new Business(); 7 | // business.active(); 8 | System.out.println("it's finished"); 9 | } 10 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ServiceOrDaoClassShouldEndWithImplRule.html: -------------------------------------------------------------------------------- 1 | All Service and DAO classes must be interface based on SOA principle. Implementation class names should be ended with Impl. 2 |
Examples:
3 |4 | public interface DemoService{ 5 | void f(); 6 | } 7 | public class DemoServiceImpl implements DemoService { 8 | @Override 9 | public void f(){ 10 | System.out.println("hello world"); 11 | } 12 | } 13 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/StringConcatRule.html: -------------------------------------------------------------------------------- 1 | Use the append method in StringBuilder inside a loop body when concatenating multiple strings. 2 |
Examples:
3 |4 | Negative example: 5 | String result; 6 | for (String string : tagNameList) { 7 | result = result + string; 8 | } 9 | 10 | Positive example: 11 | StringBuilder stringBuilder = new StringBuilder(); 12 | for (String string : tagNameList) { 13 | stringBuilder.append(string); 14 | } 15 | String result = stringBuilder.toString(); 16 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/SwitchStatementRule.html: -------------------------------------------------------------------------------- 1 | In a switch block, each case should be finished by break/return. If not, a note should be included to describe at which case it will stop. Within every switch block, a default statement must be present, even if it is empty. 2 |
Examples:
3 |4 | switch (x) { 5 | case 1: 6 | break; 7 | case 2: 8 | break; 9 | default: 10 | } 11 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/TestClassShouldEndWithTestNamingRule.html: -------------------------------------------------------------------------------- 1 | Test cases shall be started with the class names to be tested and ended with Test. 2 |
Examples:
3 |4 | public class DemoTest { 5 | } 6 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ThreadLocalShouldRemoveRule.html: -------------------------------------------------------------------------------- 1 | Customized ThreadLocal variables must be recycled,especially when using thread pools in which threads are often reused. Otherwise, it may affect subsequent business logic and cause unexpected problems such as memory leak. 2 |
Examples:
3 |4 | /** 5 | * @author caikang 6 | * @date 2017/04/07 7 | */ 8 | public class UserHolder { 9 | private static final ThreadLocal-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ThreadPoolCreationRule.html: -------------------------------------------------------------------------------- 1 | A thread pool should be created by ThreadPoolExecutor rather than Executors. These would make the parameters of the thread pool understandable. It would also reduce the risk of running out of system resource. 2 |userThreadLocal = new ThreadLocal (); 10 | public static void set(User user){ 11 | userThreadLocal.set(user); 12 | } 13 | public static User get(){ 14 | return userThreadLocal.get(); 15 | } 16 | public static void remove(){ 17 | userThreadLocal.remove(); 18 | } 19 | } 20 | /** 21 | * @author caikang 22 | * @date 2017/04/07 23 | */ 24 | public class UserInterceptor extends HandlerInterceptorAdapter { 25 | @Override 26 | public boolean preHandle(HttpServletRequest request, 27 | HttpServletResponse response, Object handler) throws Exception { 28 | UserHolder.set(new User()); 29 | return true; 30 | } 31 | @Override 32 | public void afterCompletion(HttpServletRequest request, 33 | HttpServletResponse response, Object handler, Exception ex) throws Exception { 34 | UserHolder.remove(); 35 | } 36 | } 37 |
Examples:
3 |4 | Positive example 1: 5 | //org.apache.commons.lang3.concurrent.BasicThreadFactory 6 | ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, new BasicThreadFactory.Builder().namingPattern("example-schedule-pool-%d").daemon(true).build()); 7 | 8 | Positive example 2: 9 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() 10 | .setNameFormat("demo-pool-%d").build(); 11 | //Common Thread Pool 12 | ExecutorService pool = new ThreadPoolExecutor(5, 200, 13 | 0L, TimeUnit.MILLISECONDS, 14 | new LinkedBlockingQueue-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ThreadShouldSetNameRule.html: -------------------------------------------------------------------------------- 1 | A meaningful thread name is helpful to trace the error information,so assign a name when creating threads or thread pools. 2 |(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); 15 | pool.execute(()-> System.out.println(Thread.currentThread().getName())); 16 | pool.shutdown();//gracefully shutdown 17 | 18 | Positive example 3: 19 | 21 | 29 | //in code 30 | userThreadPool.execute(thread); 31 |22 | 23 | 24 | 25 | 26 | 27 | 28 |
Examples:
3 |4 | Positive example 1: 5 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() 6 | .setNameFormat("demo-pool-%d").build(); 7 | ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1, 8 | 0L, TimeUnit.MILLISECONDS, 9 | new LinkedBlockingQueue-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/TransactionMustHaveRollbackRule.html: -------------------------------------------------------------------------------- 1 | Make sure to invoke the rollback if a method throws an Exception. 2 |(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); 10 | singleThreadPool.execute(()-> System.out.println(Thread.currentThread().getName())); 11 | singleThreadPool.shutdown(); 12 | 13 | Positive example 2: 14 | public class TimerTaskThread extends Thread { 15 | public TimerTaskThread(){ 16 | super.setName("TimerTaskThread"); … 17 | } 18 |
Examples:
3 |4 | Positive example 1: 5 | /** 6 | * @author caikang 7 | * @date 2017/04/07 8 | */ 9 | @Service 10 | @Transactional(rollbackFor = Exception.class) 11 | public class UserServiceImpl implements UserService { 12 | @Override 13 | public void save(User user) { 14 | //some code 15 | //db operation 16 | } 17 | } 18 | Positive example 2: 19 | /** 20 | * @author caikang 21 | * @date 2017/04/07 22 | */ 23 | @Service 24 | public class UserServiceImpl implements UserService { 25 | @Override 26 | @Transactional(rollbackFor = Exception.class) 27 | public void save(User user) { 28 | //some code 29 | //db operation 30 | } 31 | } 32 | Positive example 3: 33 | /** 34 | * @author caikang 35 | * @date 2017/04/07 36 | */ 37 | @Service 38 | public class UserServiceImpl implements UserService { 39 | @Autowired 40 | private DataSourceTransactionManager transactionManager; 41 | @Override 42 | @Transactional 43 | public void save(User user) { 44 | DefaultTransactionDefinition def = new DefaultTransactionDefinition(); 45 | // explicitly setting the transaction name is something that can only be done programmatically 46 | def.setName("SomeTxName"); 47 | def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); 48 | TransactionStatus status = transactionManager.getTransaction(def); 49 | try { 50 | // execute your business logic here 51 | //db operation 52 | } catch (Exception ex) { 53 | transactionManager.rollback(status); 54 | throw ex; 55 | } 56 | } 57 | } 58 |59 | 60 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UndefineMagicConstantRule.html: -------------------------------------------------------------------------------- 1 | Magic values, except for predefined, are forbidden in coding. 2 |
Examples:
3 |4 | Negative example: 5 | //Magic values, except for predefined, are forbidden in coding. 6 | if (key.equals("Id#taobao_1")) { 7 | //... 8 | } 9 | Positive example: 10 | String KEY_PRE = "Id#taobao_1"; 11 | if (KEY_PRE.equals(key)) { 12 | //... 13 | } 14 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UnsupportedExceptionWithModifyAsListRule.html: -------------------------------------------------------------------------------- 1 | Do not use methods which will modify the list after using Arrays.asList to convert array to list, otherwise methods like add/remove/clear will throw UnsupportedOperationException. 2 |
Examples:
3 |4 | Positive example: 5 | List-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UpperEllRule.html: -------------------------------------------------------------------------------- 1 | 'L' instead of 'l' should be used for long or Long variable because 'l' is easily to be regarded as number 1 in mistake. 2 |t = Arrays.asList("a","b","c"); 6 | //warn 7 | t.add("22"); 8 | //warn 9 | t.remove("22"); 10 | //warn 11 | t.clear(); 12 | 13 |
Examples:
3 |4 | Negative example: 5 | //It is hard to tell whether it is number 11 or Long 1. 6 | Long warn = 1l; 7 | 8 | Positive example: 9 | Long notwarn = 1L; 10 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UseRightCaseForDateFormatRule.html: -------------------------------------------------------------------------------- 1 | When doing date formatting, "yyyy" represents the day in which year, while "YYYY" represents the week in which 2 | * year (a concept introduced in JDK7). If a week is across two years, the returning "YYYY"represents the next year. 3 |
Examples:
4 |5 | Negative example: 6 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 7 | 8 | Positive example: 9 | SimpleDateFormat format = new SimpleDateFormat("YYYY-mm-dd HH:mm:ss"); 10 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/WrapperTypeEqualityRule.html: -------------------------------------------------------------------------------- 1 | The wrapper classes should be compared by equals method rather than by symbol of '==' directly. 2 |
Examples:
3 |4 | Integer a = 235; 5 | Integer b = 235; 6 | if (a.equals(b)) { 7 | // code 8 | } 9 |-------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnit4SuitesShouldUseSuiteAnnotation.html: -------------------------------------------------------------------------------- 1 | In JUnit 3, test suites are indicated by the suite() method. In JUnit 4, suites are indicated 2 | through the @RunWith(Suite.class) annotation. Example: 3 |
4 | public class BadExample extends TestCase{ 5 | 6 | public static Test suite(){ 7 | return new Suite(); 8 | } 9 | } 10 | 11 | @RunWith(Suite.class) 12 | @SuiteClasses( { TestOne.class, TestTwo.class }) 13 | public class GoodTest { 14 | } 15 |16 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnit4TestShouldUseAfterAnnotation.html: -------------------------------------------------------------------------------- 1 | In JUnit 3, the tearDown method was used to clean up all data entities required in running tests. 2 | JUnit 4 skips the tearDown method and executes all methods annotated with @After after running each test Example: 3 |
4 | public class MyTest { 5 | public void tearDown() { 6 | bad(); 7 | } 8 | } 9 | public class MyTest2 { 10 | @After public void tearDown() { 11 | good(); 12 | } 13 | } 14 |15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnit4TestShouldUseBeforeAnnotation.html: -------------------------------------------------------------------------------- 1 | In JUnit 3, the setUp method was used to set up all data entities required in running tests. 2 | JUnit 4 skips the setUp method and executes all methods annotated with @Before before all tests Example: 3 |
4 | public class MyTest { 5 | public void setUp() { 6 | bad(); 7 | } 8 | } 9 | public class MyTest2 { 10 | @Before public void setUp() { 11 | good(); 12 | } 13 | } 14 |15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnit4TestShouldUseTestAnnotation.html: -------------------------------------------------------------------------------- 1 | In JUnit 3, the framework executed all methods which started with the word test as a unit test. 2 | In JUnit 4, only methods annotated with the @Test annotation are executed. Example: 3 |
4 | public class MyTest { 5 | public void testBad() { 6 | doSomething(); 7 | } 8 | 9 | @Test 10 | public void testGood() { 11 | doSomething(); 12 | } 13 | } 14 |15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitAssertionsShouldIncludeMessage.html: -------------------------------------------------------------------------------- 1 | JUnit assertions should include a message - i.e., use the three argument version of assertEquals(), not the two argument version. 2 |
3 | public class Foo extends TestCase { 4 | public void testSomething() { 5 | assertEquals("foo", "bar"); // violation, should be assertEquals("Foo does not equals bar", "foo", "bar"); 6 | } 7 | } 8 |9 | 10 |
11 | This rule is deprecated, use {rule:squid:S2698} instead. 12 |
13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitSpelling.html: -------------------------------------------------------------------------------- 1 | Some JUnit framework methods are easy to misspell. 2 |3 | import junit.framework.*; 4 | 5 | public class Foo extends TestCase { 6 | public void setup() {} // violation, should be setUp() 7 | public void TearDown() {} // violation, should be tearDown() 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitStaticSuite.html: -------------------------------------------------------------------------------- 1 | The suite() method in a JUnit test needs to be both public and static. 2 |
3 | import junit.framework.*; 4 | 5 | public class Foo extends TestCase { 6 | public void suite() {} // violation, should be static 7 | private static void suite() {} // violation, should be public 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestContainsTooManyAsserts.html: -------------------------------------------------------------------------------- 1 | JUnit tests should not contain too many asserts. Many asserts are indicative of a complex test, for which 2 | it is harder to verify correctness. Consider breaking the test scenario into multiple, shorter test scenarios. 3 | Customize the maximum number of assertions used by this Rule to suit your needs. Example: 4 |
5 | public class MyTestCase extends TestCase { 6 | // Ok 7 | public void testMyCaseWithOneAssert() { 8 | boolean myVar = false; 9 | assertFalse("should be false", myVar); 10 | } 11 | 12 | // Bad, too many asserts (assuming max=1) 13 | public void testMyCaseWithMoreAsserts() { 14 | boolean myVar = false; 15 | assertFalse("myVar should be false", myVar); 16 | assertEquals("should equals false", false, myVar); 17 | } 18 | } 19 |20 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestsShouldIncludeAssert.html: -------------------------------------------------------------------------------- 1 | JUnit tests should include at least one assertion. This makes the tests more robust, and using assert with messages provide the developer a clearer idea of what the test does. 2 |
3 | public class Foo extends TestCase { 4 | public void testSomething() { 5 | Bar b = findBar(); 6 | b.work(); 7 | // violation, we could use assertNotNull("bar not found", b); 8 | } 9 | } 10 |11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitUseExpected.html: -------------------------------------------------------------------------------- 1 | In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions. Example: 2 |
3 | public class MyTest { 4 | @Test 5 | public void testBad() { 6 | try { 7 | doSomething(); 8 | fail("should have thrown an exception"); 9 | } catch (Exception e) { 10 | } 11 | } 12 | 13 | @Test(expected=Exception.class) 14 | public void testGood() { 15 | doSomething(); 16 | } 17 | } 18 |19 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/SimplifyBooleanAssertion.html: -------------------------------------------------------------------------------- 1 | Avoid negation in an assertTrue or assertFalse test. For example, rephrase: assertTrue(!expr); as: assertFalse(expr); 2 |
3 | public class SimpleTest extends TestCase { 4 | public void testX() { 5 | assertTrue("not empty", !r.isEmpty()); // violation, replace with assertFalse("not empty", r.isEmpty()) 6 | assertFalse(!r.isEmpty()); // violation, replace with assertTrue("empty", r.isEmpty()) 7 | } 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/TestClassWithoutTestCases.html: -------------------------------------------------------------------------------- 1 | Test classes end with the suffix Test. Having a non-test class with that name is not a good practice, since most people will assume it is a test case. Test classes have test methods named testXXX. 2 | Beware: This rule doesn't support JUnit 4.x's @Test annotation. 3 |
4 | public class CarTest { // violation, consider changing the name of the class if it is not a test 5 | // consider adding test methods if it is a test 6 | public static void main(String[] args) { 7 | // do something 8 | } 9 | } 10 |11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UnnecessaryBooleanAssertion.html: -------------------------------------------------------------------------------- 1 | A JUnit test assertion with a boolean literal is unnecessary since it always will eval to the same thing. Consider using flow control (in case of assertTrue(false) or similar) or simply removing statements like assertTrue(true) and assertFalse(false). If you just want a test to halt, use the fail method. 2 |
3 | public class SimpleTest extends TestCase { 4 | public void testX() { 5 | assertTrue(true); // violation 6 | } 7 | }8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertEqualsInsteadOfAssertTrue.html: -------------------------------------------------------------------------------- 1 | This rule detects JUnit assertions in object equality. These assertions should be made by more specific methods, like assertEquals. 2 |
3 | public class FooTest extends TestCase { 4 | void testCode() { 5 | Object a, b; 6 | 7 | assertTrue(a.equals(b)); // violation 8 | assertEquals("a should equals b", a, b); // good usage 9 | } 10 | }11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertNullInsteadOfAssertTrue.html: -------------------------------------------------------------------------------- 1 | This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertNull, assertNotNull. 2 |
3 | public class FooTest extends TestCase { 4 | void testCode() { 5 | Object a = doSomething(); 6 | 7 | assertTrue(a==null); // violation 8 | assertNull(a); // good usage 9 | assertTrue(a != null); // violation 10 | assertNotNull(a); // good usage 11 | } 12 | } 13 |14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertSameInsteadOfAssertTrue.html: -------------------------------------------------------------------------------- 1 | This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertSame, assertNotSame. 2 |
3 | public class FooTest extends TestCase { 4 | void testCode() { 5 | Object a, b; 6 | 7 | assertTrue(a==b); // violation 8 | assertSame(a, b); // good usage 9 | } 10 | } 11 |12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertTrueInsteadOfAssertEquals.html: -------------------------------------------------------------------------------- 1 | When asserting a value is the same as a boolean literal, use assertTrue/assertFalse, instead of assertEquals. Example: 2 |
3 | public class MyTestCase extends TestCase { 4 | public void testMyCase() { 5 | boolean myVar = true; 6 | // Ok 7 | assertTrue("myVar is true", myVar); 8 | // Bad 9 | assertEquals("myVar is true", true, myVar); 10 | // Bad 11 | assertEquals("myVar is false", false, myVar); 12 | } 13 | } 14 |15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AbstractClassWithoutAbstractMethod.html: -------------------------------------------------------------------------------- 1 | The abstract class does not contain any abstract methods. An abstract class suggests an incomplete implementation, which is to be completed by subclasses implementing the abstract methods. If the class is intended to be used as a base class only (not to be instantiated direcly) a protected constructor can be provided prevent direct instantiation. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1694} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AbstractClassWithoutAnyMethod.html: -------------------------------------------------------------------------------- 1 | If the abstract class does not provides any methods, it may be just a data container that is not to be instantiated. In this case, it's probably better to use a private or a protected constructor in order to prevent instantiation than make the class misleadingly abstract. Example : 2 |3 | public class abstract Example { 4 | String field; 5 | int otherField; 6 | } 7 |8 | 9 |
10 | This rule is deprecated, use {rule:squid:S1694} instead. 11 |
12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AbstractNaming.html: -------------------------------------------------------------------------------- 1 | Abstract classes should be named 'AbstractXXX'. Example : 2 |3 | public abstract class Foo { // should be AbstractFoo 4 | } 5 |6 | 7 |
8 | This rule is deprecated, use {rule:squid:S00118} instead. 9 |
10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AccessorClassGeneration.html: -------------------------------------------------------------------------------- 1 | Instantiation by way of private constructors from outside of the constructor's class often causes the generation of an accessor. A factory method, or non-privitization of the constructor can eliminate this situation. The generated class file is actually an interface. It gives the accessing class the ability to invoke a new hidden package scope constructor that takes the interface as a supplementary parameter. This turns a private constructor effectively into one with package scope, and is challenging to discern. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AddEmptyString.html: -------------------------------------------------------------------------------- 1 | Finds empty string literals which are being added. This is an inefficient way to convert any type to a String. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2131} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AppendCharacterWithChar.html: -------------------------------------------------------------------------------- 1 | Avoid concatenating characters as strings in StringBuffer.append. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ArrayIsStoredDirectly.html: -------------------------------------------------------------------------------- 1 | Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2384} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AssignmentInOperand.html: -------------------------------------------------------------------------------- 1 | Avoid assignments in operands; this can make code more complicated and harder to read. 2 | 3 |4 | This rule is deprecated, use {rule:squid:AssignmentInSubExpressionCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AssignmentToNonFinalStatic.html: -------------------------------------------------------------------------------- 1 | Identifies a possible unsafe usage of a static field. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AtLeastOneConstructor.html: -------------------------------------------------------------------------------- 1 | Each class should declare at least one constructor. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1118} or {rule:squid:S1258} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidAccessibilityAlteration.html: -------------------------------------------------------------------------------- 1 | Methods such as getDeclaredConstructors(), getDeclaredConstructor(Class[]) and setAccessible(), as the interface PrivilegedAction, allow to alter, at runtime, the visilibilty of variable, classes, or methods, even if they are private. Obviously, no one should do so, as such behavior is against everything encapsulation principal stands for. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidArrayLoops.html: -------------------------------------------------------------------------------- 1 | Instead of copying data between two arrays, use System.arrayCopy method 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidAssertAsIdentifier.html: -------------------------------------------------------------------------------- 1 | Finds all places 'assert' is used as an identifier is used. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1190} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidBranchingStatementAsLastInLoop.html: -------------------------------------------------------------------------------- 1 | Using a branching statement as the last part of a loop may be a bug, and/or is confusing. 2 | Ensure that the usage is not a bug, or consider using another approach. Example: 3 |4 | // unusual use of branching statement in a loop 5 | for (int i = 0; i < 10; i++) { 6 | if (i*i <= 25) { 7 | continue; 8 | } 9 | break; 10 | } 11 | 12 | // this makes more sense... 13 | for (int i = 0; i < 10; i++) { 14 | if (i*i > 25) { 15 | break; 16 | } 17 | } 18 |19 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidCallingFinalize.html: -------------------------------------------------------------------------------- 1 | Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:ObjectFinalizeCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidCatchingGenericException.html: -------------------------------------------------------------------------------- 1 | Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2221} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidCatchingNPE.html: -------------------------------------------------------------------------------- 1 | Code should never throw NPE under normal circumstances. A catch block may hide the original error, causing other more subtle errors in its wake. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1696} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidCatchingThrowable.html: -------------------------------------------------------------------------------- 1 | This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1181} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidConstantsInterface.html: -------------------------------------------------------------------------------- 1 | An interface should be used only to model a behaviour of a class: using an interface as a container of constants is a poor usage pattern. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1214} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidDecimalLiteralsInBigDecimalConstructor.html: -------------------------------------------------------------------------------- 1 | One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2111} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidDeeplyNestedIfStmts.html: -------------------------------------------------------------------------------- 1 | Deeply nested if..then statements are hard to read. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S134} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidDollarSigns.html: -------------------------------------------------------------------------------- 1 |2 | Avoid using dollar signs in variable/method/class/interface names. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00114}, {rule:squid:S00115}, {rule:squid:S00116} and {rule:squid:S00117} 7 | instead. 8 |
9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidDuplicateLiterals.html: -------------------------------------------------------------------------------- 1 | Code containing duplicate String literals can usually be improved by declaring the String as a constant field. Example : 2 |3 | public class Foo { 4 | private void bar() { 5 | buz("Howdy"); 6 | buz("Howdy"); 7 | buz("Howdy"); 8 | buz("Howdy"); 9 | } 10 | private void buz(String x) {} 11 | } 12 |13 | 14 |
15 | This rule is deprecated, use {rule:squid:S1192} instead. 16 |
17 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidEnumAsIdentifier.html: -------------------------------------------------------------------------------- 1 | Finds all places 'enum' is used as an identifier is used. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1190} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidFieldNameMatchingMethodName.html: -------------------------------------------------------------------------------- 1 | It is somewhat confusing to have a field name with the same name as a method. While this is totally legal, having information (field) and actions (method) is not clear naming. Example : 2 |3 | public class Foo { 4 | Object bar; 5 | // bar is data or an action or both? 6 | void bar() { 7 | } 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S1845} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidFieldNameMatchingTypeName.html: -------------------------------------------------------------------------------- 1 | It is somewhat confusing to have a field name matching the declaring class name. This probably means that type and or field names could be more precise. Example : 2 |3 | public class Foo extends Bar { 4 | // There's probably a better name for foo 5 | int foo; 6 | } 7 |8 | 9 |
10 | This rule is deprecated, use {rule:squid:S1700} instead. 11 |
12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidFinalLocalVariable.html: -------------------------------------------------------------------------------- 1 | Avoid using final local variables, turn them into fields. Example : 2 |3 | public class MyClass { 4 | public void foo() { 5 | final String finalLocalVariable; 6 | } 7 | } 8 |9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidInstanceofChecksInCatchClause.html: -------------------------------------------------------------------------------- 1 | Each caught exception type should be handled in its own catch clause. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1193} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidInstantiatingObjectsInLoops.html: -------------------------------------------------------------------------------- 1 | Detects when a new object is created inside a loop 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidLiteralsInIfCondition.html: -------------------------------------------------------------------------------- 1 | Avoid using hard coded literals in conditional statements, declare those as static variables or private members. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S109} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidLosingExceptionInformation.html: -------------------------------------------------------------------------------- 1 | Statements in a catch block that invoke accessors on the exception without using the information only add to code size. Either remove the invocation, or use the return result. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1166} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidMultipleUnaryOperators.html: -------------------------------------------------------------------------------- 1 | Using multiple unary operators may be a bug, and/or is confusing. Check the usage is not a bug, or consider simplifying the expression. Example : 2 |3 | // These are typo bugs, or at best needlessly complex and confusing: 4 | int i = - -1; 5 | int j = + - +1; 6 | int z = ~~2; 7 | boolean b = !!true; 8 | boolean c = !!!true; 9 | 10 | // These are better: 11 | int i = 1; 12 | int j = -1; 13 | int z = 2; 14 | boolean b = true; 15 | boolean c = false; 16 | 17 | // And these just make your brain hurt: 18 | int i = ~-2; 19 | int j = -~7; 20 |21 | 22 |
23 | This rule is deprecated, use {rule:squid:S881} instead. 24 |
25 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidPrefixingMethodParameters.html: -------------------------------------------------------------------------------- 1 | Prefixing parameters by 'in' or 'out' pollutes the name of the parameters and reduces code readability. 2 | To indicate whether or not a parameter will be modify in a method, its better to document method 3 | behavior with Javadoc. Example: 4 |5 | // Not really clear 6 | public class Foo { 7 | public void bar( 8 | int inLeftOperand, 9 | Result outRightOperand) { 10 | outRightOperand.setValue(inLeftOperand * outRightOperand.getValue()); 11 | } 12 | } 13 |14 | 15 |
16 | This rule is deprecated, use {rule:squid:S00117} instead. 17 |
18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidPrintStackTrace.html: -------------------------------------------------------------------------------- 1 | Avoid printStackTrace(); use a logger call instead. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1148} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidProtectedFieldInFinalClass.html: -------------------------------------------------------------------------------- 1 | Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent by using private or package access modifiers instead. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2156} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidProtectedMethodInFinalClassNotExtending.html: -------------------------------------------------------------------------------- 1 | Do not use protected methods in most final classes since they cannot be subclassed. This should 2 | only be allowed in final classes that extend other classes with protected methods (whose 3 | visibility cannot be reduced). Clarify your intent by using private or package access modifiers instead. Example: 4 |5 | public final class Foo { 6 | private int bar() {} 7 | protected int baz() {} // Foo cannot be subclassed, and doesn't extend anything, so is baz() really private or package visible? 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S2156} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidReassigningParameters.html: -------------------------------------------------------------------------------- 1 | Reassigning values to parameters is a questionable practice. Use a temporary local variable instead. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1226} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidRethrowingException.html: -------------------------------------------------------------------------------- 1 | Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1166} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidStringBufferField.html: -------------------------------------------------------------------------------- 1 | StringBuffers can grow quite a lot, and so may become a source of memory leak (if the owning class has a long life time). Example : 2 |3 | class Foo { 4 | private StringBuffer memoryLeak; 5 | } 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:S1149} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidSynchronizedAtMethodLevel.html: -------------------------------------------------------------------------------- 1 | Method level synchronization can backfire when new code is added to the method. Block-level synchronization helps to ensure that only the code that needs synchronization gets it. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidThreadGroup.html: -------------------------------------------------------------------------------- 1 | Avoid using ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread safe. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidThrowingNewInstanceOfSameException.html: -------------------------------------------------------------------------------- 1 | Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same type only add to code size and runtime complexity. Example : 2 |3 | public class Foo { 4 | void bar() { 5 | try { 6 | // do something 7 | } catch (SomeException se) { 8 | // harmless comment 9 | throw new SomeException(se); 10 | } 11 | } 12 | } 13 |14 | 15 |
16 | This rule is deprecated, use {rule:squid:S1166} instead. 17 |
18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidThrowingNullPointerException.html: -------------------------------------------------------------------------------- 1 | Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1695} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidThrowingRawExceptionTypes.html: -------------------------------------------------------------------------------- 1 |2 | Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exception, or Error, use 3 | a subclassed exception or error instead. 4 |
5 | 6 |7 | This rule is deprecated, use {rule:squid:S00112} instead. 8 |
9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidUsingHardCodedIP.html: -------------------------------------------------------------------------------- 1 | An application with hard-coded IP addresses can become impossible to deploy in some cases. Externalizing IP addresses is preferable. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1313} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidUsingNativeCode.html: -------------------------------------------------------------------------------- 1 | As JVM and Java language offer already many help in creating application, it should be very rare to have to rely on non-java code. Even though, it is rare to actually have to use Java Native Interface (JNI). As the use of JNI make application less portable, and harder to maintain, it is not recommended. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidUsingOctalValues.html: -------------------------------------------------------------------------------- 1 | Integer literals should not start with zero. Zero means that the rest of literal will be interpreted as an octal value. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1314} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidUsingShortType.html: -------------------------------------------------------------------------------- 1 | Java uses the short type to reduce memory usage, not to optimize calculation. On the contrary, the JVM does not have arithmetic capabilities with the type short. So, the P-code must convert the short into int, then do the proper calculation and then again, convert int to short. So, use of the short type may have a great effect on memory usage. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/AvoidUsingVolatile.html: -------------------------------------------------------------------------------- 1 | Use of the keyword "volatile" is general used to fine tune a Java application, and therefore, requires a good expertise of the Java Memory Model. Morover, its range of action is somewhat misknown. Therefore, the volatile keyword should not be used for maintenance purpose and portability. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BadComparison.html: -------------------------------------------------------------------------------- 1 | Avoid equality comparisons with Double.NaN - these are likely to be logic errors. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BeanMembersShouldSerialize.html: -------------------------------------------------------------------------------- 1 | If a class is a bean, or is referenced by a bean directly or indirectly it needs to be serializable. Member variables need to be marked as transient, static, or have accessor methods in the class. Marking variables as transient is the safest and easiest modification. Accessor methods should follow the Java naming conventions, i.e.if you have a variable foo, you should provide getFoo and setFoo methods. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BigIntegerInstantiation.html: -------------------------------------------------------------------------------- 1 | Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and for 1.5 on, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN) 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BooleanGetMethodName.html: -------------------------------------------------------------------------------- 1 | Looks for methods named "getX()" with "boolean" as the return type. The convention is to name these methods "isX()". 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BooleanInstantiation.html: -------------------------------------------------------------------------------- 1 | Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/BrokenNullCheck.html: -------------------------------------------------------------------------------- 1 | The null check is broken since it will throw a Nullpointer itself. The reason is that a method is called on the object when it is null. It is likely that you used || instead of && or vice versa. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1697} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ByteInstantiation.html: -------------------------------------------------------------------------------- 1 | In JDK 1.5, calling new Byte() causes memory allocation. Byte.valueOf() is more memory friendly. Example : 2 |3 | public class Foo { 4 | private Byte i = new Byte(0); // change to Byte i = 5 | Byte.valueOf(0); 6 | } 7 |8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CallSuperFirst.html: -------------------------------------------------------------------------------- 1 | Super should be called at the start of the method. Example : 2 |
3 | public class DummyActivity extends Activity { 4 | public void onCreate(Bundle bundle) { 5 | // missing call to super.onCreate(bundle) 6 | foo(); 7 | } 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CallSuperInConstructor.html: -------------------------------------------------------------------------------- 1 | It is a good practice to call super() in a constructor. If super() is not called but another constructor (such as an overloaded constructor) is called, this rule will not report it. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CallSuperLast.html: -------------------------------------------------------------------------------- 1 | Super should be called at the end of the method. Example : 2 |
3 | public class DummyActivity extends Activity { 4 | public void onPause() { 5 | foo(); 6 | // missing call to super.onPause() 7 | } 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CheckResultSet.html: -------------------------------------------------------------------------------- 1 | Always check the return of one of the navigation method (next,previous,first,last) of a ResultSet. Indeed, if the value return is "false", the developer should deal with it ! 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CheckSkipResult.html: -------------------------------------------------------------------------------- 1 | The skip() method may skip a smaller number of bytes than requested. Check the returned value to find out if it was the case or not. Example: 2 |
3 | public class Foo { 4 | 5 | private FileInputStream _s = new FileInputStream("file"); 6 | 7 | public void skip(int n) throws IOException { 8 | _s.skip(n); // You are not sure that exactly n bytes are skipped 9 | } 10 | 11 | public void skipExactly(int n) throws IOException { 12 | while (n != 0) { 13 | long skipped = _s.skip(n); 14 | if (skipped == 0) 15 | throw new EOFException(); 16 | n -= skipped; 17 | } 18 | } 19 |20 | 21 |
22 | This rule is deprecated, use {rule:squid:S2674} instead. 23 |
24 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ClassCastExceptionWithToArray.html: -------------------------------------------------------------------------------- 1 | if you need to get an array of a class from your Collection, you should pass an array of the desidered class as the parameter of the toArray method. Otherwise you will get a ClassCastException. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ClassNamingConventions.html: -------------------------------------------------------------------------------- 1 |2 | Class names should always begin with an upper case character. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00101} and {rule:squid:S00114} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ClassWithOnlyPrivateConstructorsShouldBeFinal.html: -------------------------------------------------------------------------------- 1 | A class with only private constructors should be final, unless the private constructor is called by a inner class. Example : 2 |3 | public class Foo { //Should be final 4 | private Foo() { } 5 | } 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:S2974} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloneMethodMustBePublic.html: -------------------------------------------------------------------------------- 1 |2 | The java Manual says “By convention, classes that implement this interface should override Object.clone (which is 3 | protected) with a public method.” 4 |
5 | 6 |Examples:
7 |8 | public class Foo implements Cloneable { 9 | @Override 10 | protected Object clone() throws CloneNotSupportedException { // Violation, must be public 11 | } 12 | } 13 | 14 | public class Foo implements Cloneable { 15 | @Override 16 | protected Foo clone() { // Violation, must be public 17 | } 18 | } 19 | 20 | public class Foo implements Cloneable { 21 | @Override 22 | public Object clone() // Ok 23 | } 24 |25 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloneMethodMustImplementCloneable.html: -------------------------------------------------------------------------------- 1 | The method clone() should only be implemented if the class implements the Cloneable interface with the exception of a final method that only throws CloneNotSupportedException. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1182} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloneMethodMustImplementCloneableWithTypeResolution.html: -------------------------------------------------------------------------------- 1 | The method clone() should only be implemented if the class implements the Cloneable interface with the exception 2 | of a final method that only throws CloneNotSupportedException. This version uses PMD's type resolution facilities, 3 | and can detect if the class implements or extends a Cloneable class. Example: 4 |5 | public class MyClass { 6 | public Object clone() throws CloneNotSupportedException { 7 | return foo; 8 | } 9 | } 10 |11 | 12 |
13 | This rule is deprecated, use {rule:squid:S1182} instead. 14 |
15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloneMethodReturnTypeMustMatchClassName.html: -------------------------------------------------------------------------------- 1 |Minimum Language Version: java 1.5
2 |3 | If a class implements cloneable the return type of the method clone() must be the class name. That way, the caller of 4 | the clone method doesn’t need to cast the returned clone to the correct type. 5 |
6 |7 | Note: This is only possible with Java 1.5 or higher. 8 |
9 | 10 |Examples:
11 |12 | public class Foo implements Cloneable { 13 | @Override 14 | protected Object clone() { // Violation, Object must be Foo 15 | } 16 | } 17 | 18 | public class Foo implements Cloneable { 19 | @Override 20 | public Foo clone() { //Ok 21 | } 22 | } 23 |24 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloneThrowsCloneNotSupportedException.html: -------------------------------------------------------------------------------- 1 | The method clone() should throw a CloneNotSupportedException. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1182} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CloseResource.html: -------------------------------------------------------------------------------- 1 | Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use. It does this by looking for code patterned like : 2 |3 | Connection c = openConnection(); 4 | try { 5 | // do stuff, and maybe catch something 6 | } finally { 7 | c.close(); 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S2095} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CollapsibleIfStatements.html: -------------------------------------------------------------------------------- 1 | Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1066} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CommentContent.html: -------------------------------------------------------------------------------- 1 | A rule for the politically correct... we don't want to offend anyone. Example: 2 |3 | // OMG, this is horrible, Bob is an idiot !!! 4 |5 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CommentDefaultAccessModifier.html: -------------------------------------------------------------------------------- 1 |
2 | To avoid mistakes if we want that a Method, Field or Nested class have a default access modifier 3 | we must add a comment at the beginning of the Method, Field or Nested class. 4 | By default the comment must be /* default */, if you want another, you have to provide a regex. 5 |
6 | 7 |8 | public class Foo { 9 | final String stringValue = "some string"; 10 | String getString() { 11 | return stringValue; 12 | } 13 | 14 | class NestedFoo { 15 | } 16 | } 17 | 18 | // should be 19 | public class Foo { 20 | /* default */ final String stringValue = "some string"; 21 | /* default */ String getString() { 22 | return stringValue; 23 | } 24 | 25 | /* default */ class NestedFoo { 26 | } 27 | } 28 |29 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CommentRequired.html: -------------------------------------------------------------------------------- 1 | Denotes whether comments are required (or unwanted) for specific language elements. Example: 2 |
3 | /** 4 | * 5 | * 6 | * @author George Bush 7 | */ 8 |9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CommentSize.html: -------------------------------------------------------------------------------- 1 | Determines whether the dimensions of non-header comments found are within the specified limits. Example: 2 |
3 | /** 4 | * 5 | * too many lines! 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | */ 19 |20 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CompareObjectsWithEquals.html: -------------------------------------------------------------------------------- 1 | Use equals() to compare object references; avoid comparing them with ==. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1698} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ConfusingTernary.html: -------------------------------------------------------------------------------- 1 | In an if expression with an else clause, avoid negation in the test. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff(); Most if (x != y) cases without an else are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as does the error case go first? or does the common case go first?. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ConsecutiveAppendsShouldReuse.html: -------------------------------------------------------------------------------- 1 | Consecutively calls to StringBuffer/StringBuilder .append should reuse the target object. This can improve the performance. Example: 2 |3 | String foo = " "; 4 | 5 | StringBuffer buf = new StringBuffer(); 6 | buf.append("Hello"); // poor 7 | buf.append(foo); 8 | buf.append("World"); 9 | 10 | StringBuffer buf = new StringBuffer(); 11 | buf.append("Hello").append(foo).append("World"); // good 12 |13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ConsecutiveLiteralAppends.html: -------------------------------------------------------------------------------- 1 | Consecutively calling StringBuffer.append with String literals 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ConstructorCallsOverridableMethod.html: -------------------------------------------------------------------------------- 1 | Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object 2 | and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate 3 | the construction process completely within itself, losing the ability to call super(). 4 | If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable. 5 | Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls 6 | a private method bar() that calls a public method buz(), this denotes a problem. 7 |
9 | public class SeniorClass { 10 | public SeniorClass(){ 11 | toString(); //may throw NullPointerException if overridden 12 | } 13 | public String toString(){ 14 | return "IAmSeniorClass"; 15 | } 16 | } 17 | public class JuniorClass extends SeniorClass { 18 | private String name; 19 | public JuniorClass(){ 20 | super(); //Automatic call leads to NullPointerException 21 | name = "JuniorClass"; 22 | } 23 | public String toString(){ 24 | return name.toUpperCase(); 25 | } 26 | } 27 |28 | 29 |
30 | This rule is deprecated, use {rule:squid:S1699} instead. 31 |
32 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CouplingBetweenObjects.html: -------------------------------------------------------------------------------- 1 | This rule counts unique attributes, local variables and return types within an object. A number higher than specified threshold can indicate a high degree of coupling. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1200} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/CyclomaticComplexity.html: -------------------------------------------------------------------------------- 1 |2 | Complexity is determined by the number of decision points in a method plus one for the method entry. The decision 3 | points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate 4 | complexity, 8-10 is high complexity, and 11+ is very high complexity. 5 |
6 | 7 |8 | This rule is deprecated, use {rule:squid:MethodCyclomaticComplexity} or {rule:squid:ClassCyclomaticComplexity} 9 | instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DataflowAnomalyAnalysis.html: -------------------------------------------------------------------------------- 1 | The dataflow analysis tracks local definitions, undefinitions and references to variables on different paths on the data flow. From those informations there can be found various problems. 1. UR - Anomaly: There is a reference to a variable that was not defined before. This is a bug and leads to an error. 2. DU - Anomaly: A recently defined variable is undefined. These anomalies may appear in normal source text. 3. DD - Anomaly: A recently defined variable is redefined. This is ominous but don't have to be a bug. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DefaultLabelNotLastInSwitchStmt.html: -------------------------------------------------------------------------------- 1 | Switch statements should have a default label. Example : 2 |3 | public class Foo { 4 | void bar(int a) { 5 | switch (a) { 6 | case 1: // do something 7 | break; 8 | default: // the default case should be last, by convention 9 | break; 10 | case 2: 11 | break; 12 | } 13 | } 14 | } 15 |16 | 17 |
18 | This rule is deprecated, use {rule:squid:SwitchLastCaseIsDefaultCheck} instead. 19 |
20 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DefaultPackage.html: -------------------------------------------------------------------------------- 1 | Use explicit scoping instead of the default package private level. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotCallGarbageCollectionExplicitly.html: -------------------------------------------------------------------------------- 1 | Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advised. Code should have the same behavior whether the garbage collection is disabled using the option -Xdisableexplicitgc or not. Moreover, "modern" jvms do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself. Example : 2 |3 | public class GCCall 4 | { 5 | public GCCall() 6 | { 7 | // Explicit gc call ! 8 | System.gc(); 9 | } 10 | public void doSomething() 11 | { 12 | // Explicit gc call ! 13 | Runtime.getRuntime().gc(); 14 | } 15 | 16 | public explicitGCcall() { // Explicit gc call ! System.gc(); } 17 | 18 | public void doSomething() { // Explicit gc call ! Runtime.getRuntime().gc(); } 19 | } 20 |21 | 22 |
23 | This rule is deprecated, use {rule:squid:S1215} instead. 24 |
25 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotCallSystemExit.html: -------------------------------------------------------------------------------- 1 | Web applications should not call System.exit(), since only the web container or the application server should stop the JVM. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1147} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotExtendJavaLangError.html: -------------------------------------------------------------------------------- 1 | Errors are system exceptions. Do not extend them. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1194} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotHardCodeSDCard.html: -------------------------------------------------------------------------------- 1 | Use Environment.getExternalStorageDirectory() instead of "/sdcard". 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotThrowExceptionInFinally.html: -------------------------------------------------------------------------------- 1 | Throwing exception in a finally block is confusing. It may mask exception or a defect of the code, it also render code cleanup uninstable. Example : 2 |3 | public class Foo 4 | { 5 | public void bar() 6 | { 7 | try { 8 | // Here do some stuff 9 | } 10 | catch( Exception e) { 11 | // Handling the issue 12 | } 13 | finally 14 | { 15 | // is this really a good idea ? 16 | throw new Exception(); 17 | } 18 | } 19 | } 20 |21 | 22 |
23 | This rule is deprecated, use {rule:squid:S1163} instead. 24 |
25 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoNotUseThreads.html: -------------------------------------------------------------------------------- 1 | The J2EE specification explicitly forbid use of threads. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DontCallThreadRun.html: -------------------------------------------------------------------------------- 1 | Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1217} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DontImportJavaLang.html: -------------------------------------------------------------------------------- 1 | Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3). 2 | 3 |4 | This rule is deprecated, use {rule:squid:UselessImportCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DontImportSun.html: -------------------------------------------------------------------------------- 1 | Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1191} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DontUseFloatTypeForLoopIndices.html: -------------------------------------------------------------------------------- 1 | Don't use floating point for loop indices. If you must use floating point, use double 2 | unless you're certain that float provides enough precision and you have a compelling 3 | performance need (space or time). Example: 4 |5 | public class Count { 6 | public static void main(String[] args) { 7 | final int START = 2000000000; 8 | int count = 0; 9 | for (float f = START; f < START + 50; f++) 10 | count++; 11 | //Prints 0 because (float) START == (float) (START + 50). 12 | System.out.println(count); 13 | //The termination test misbehaves due to floating point granularity. 14 | } 15 | } 16 |17 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DoubleCheckedLocking.html: -------------------------------------------------------------------------------- 1 | Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. 2 | More details. Example : 3 |
4 | public class Foo { 5 | Object baz; 6 | Object bar() { 7 | if(baz == null) { //baz may be non-null yet not fully created 8 | synchronized(this){ 9 | if(baz == null){ 10 | baz = new Object(); 11 | } 12 | } 13 | } 14 | return baz; 15 | } 16 | } 17 |18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/DuplicateImports.html: -------------------------------------------------------------------------------- 1 | Avoid duplicate import statements. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:UselessImportCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyCatchBlock.html: -------------------------------------------------------------------------------- 1 |2 | Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this 3 | swallows an exception which should either be acted on or reported. 4 |
5 | 6 |7 | This rule is deprecated, use {rule:squid:S00108} instead. 8 |
9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyFinalizer.html: -------------------------------------------------------------------------------- 1 |If the finalize() method is empty, then it does not need to exist.
2 | 3 |4 | This rule is deprecated, use {rule:squid:S1186} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyFinallyBlock.html: -------------------------------------------------------------------------------- 1 |2 | Avoid empty finally blocks - these can be deleted. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00108} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyIfStmt.html: -------------------------------------------------------------------------------- 1 |2 | Empty If Statement finds instances where a condition is checked but nothing is done about it. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00108} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyInitializer.html: -------------------------------------------------------------------------------- 1 | An empty initializer was found. Example : 2 |3 | public class Foo { 4 | 5 | static {} // Why ? 6 | 7 | {} // Again, why ? 8 | 9 | } 10 |11 | 12 |
13 | This rule is deprecated, use {rule:squid:S00108} instead. 14 |
15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyMethodInAbstractClassShouldBeAbstract.html: -------------------------------------------------------------------------------- 1 | An empty method in an abstract class should be abstract instead, as developer may rely on this empty implementation rather than code the appropriate one. 2 |3 | public abstract class ShouldBeAbstract 4 | { 5 | public Object couldBeAbstract() 6 | { 7 | // Should be abstract method ? 8 | return null; 9 | } 10 | 11 | public void couldBeAbstract() 12 | { 13 | } 14 | } 15 |16 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyStatementBlock.html: -------------------------------------------------------------------------------- 1 | Empty block statements serve no purpose and should be removed. Example: 2 |
3 | public class Foo { 4 | 5 | private int _bar; 6 | 7 | public void setBar(int bar) { 8 | { _bar = bar; } // Why not? 9 | {} // But remove this. 10 | } 11 | 12 | } 13 |14 | 15 |
16 | This rule is deprecated, use {rule:squid:S00108} instead. 17 |
18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyStatementNotInLoop.html: -------------------------------------------------------------------------------- 1 | An empty statement (aka a semicolon by itself) that is not used as the sole body of a for loop or while loop is probably a bug. It could also be a double semicolon, which is useless and should be removed. 2 | 3 |4 | This rule is deprecated, use {rule:squid:EmptyStatementUsageCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyStaticInitializer.html: -------------------------------------------------------------------------------- 1 | An empty static initializer was found. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00108} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptySwitchStatements.html: -------------------------------------------------------------------------------- 1 | Avoid empty switch statements. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00108} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptySynchronizedBlock.html: -------------------------------------------------------------------------------- 1 | Avoid empty synchronized blocks - they're useless. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00108} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyTryBlock.html: -------------------------------------------------------------------------------- 1 | Avoid empty try blocks - what's the point? 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00108} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EmptyWhileStmt.html: -------------------------------------------------------------------------------- 1 | Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00108} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/EqualsNull.html: -------------------------------------------------------------------------------- 1 | Inexperienced programmers sometimes confuse comparison concepts and use equals() to compare to null. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2159} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExceptionAsFlowControl.html: -------------------------------------------------------------------------------- 1 | Using Exceptions as flow control leads to GOTOish code and obscures true exceptions when debugging. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1141} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExcessiveClassLength.html: -------------------------------------------------------------------------------- 1 | Long Class files are indications that the class may be trying to do too much. Try to break it down, and reduce the size to something manageable. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1448} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExcessiveImports.html: -------------------------------------------------------------------------------- 1 | A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1200} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExcessiveMethodLength.html: -------------------------------------------------------------------------------- 1 | Violations of this rule usually indicate that the method is doing too much. Try to reduce the method size by creating helper methods and removing any copy/pasted code. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S138} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExcessiveParameterList.html: -------------------------------------------------------------------------------- 1 |2 | Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. Basically, try 3 | to group the parameters together. 4 |
5 | 6 |7 | This rule is deprecated, use {rule:squid:S00107} instead. 8 |
9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExcessivePublicCount.html: -------------------------------------------------------------------------------- 1 | A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1448} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ExtendsObject.html: -------------------------------------------------------------------------------- 1 | No need to explicitly extend Object. Example: 2 |3 | public class Foo extends Object { // not required 4 | } 5 |6 | 7 |
8 | This rule is deprecated, use {rule:squid:S1939} instead. 9 |
10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FieldDeclarationsShouldBeAtStartOfClass.html: -------------------------------------------------------------------------------- 1 | Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes. Example: 2 |3 | public class HelloWorldBean { 4 | 5 | // Field declared before methods / inner classes - OK 6 | private String _thing; 7 | 8 | public String getMessage() { 9 | return "Hello World!"; 10 | } 11 | 12 | // Field declared after methods / inner classes - avoid this 13 | private String _fieldInWrongLocation; 14 | } 15 |16 | 17 |
18 | This rule is deprecated, use {rule:squid:S1213} instead. 19 |
20 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FinalFieldCouldBeStatic.html: -------------------------------------------------------------------------------- 1 | If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object at runtime. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1170} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FinalizeDoesNotCallSuperFinalize.html: -------------------------------------------------------------------------------- 1 | If the finalize() is implemented, its last action should be to call super.finalize. 2 | 3 |4 | This rule is deprecated, use {rule:squid:ObjectFinalizeOverridenCallsSuperFinalizeCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FinalizeOnlyCallsSuperFinalize.html: -------------------------------------------------------------------------------- 1 | If the finalize() is implemented, it should do something besides just calling super.finalize(). 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1185} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FinalizeOverloaded.html: -------------------------------------------------------------------------------- 1 | Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1175} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/FinalizeShouldBeProtected.html: -------------------------------------------------------------------------------- 1 | If you override finalize(), make it protected. If you make it public, other classes may call it. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1174} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ForLoopShouldBeWhileLoop.html: -------------------------------------------------------------------------------- 1 | Some for loops can be simplified to while loops - this makes them more concise. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1264} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ForLoopsMustUseBraces.html: -------------------------------------------------------------------------------- 1 |
2 | Avoid using 'for' statements without using curly braces, like for (int i=0; i<42;i++) foo();
3 |
6 | This rule is deprecated, use {rule:squid:S00121} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/GenericsNaming.html: -------------------------------------------------------------------------------- 1 | Generics names should be a one letter long and upper case. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00119} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/GodClass.html: -------------------------------------------------------------------------------- 1 | The God Class rule detects the God Class design flaw using metrics. God classes do too many things, 2 | are very big and overly complex. They should be split apart to be more object-oriented. 3 | The rule uses the detection strategy described in "Object-Oriented Metrics in Practice". 4 | The violations are reported against the entire class. See also the references: 5 | Michele Lanza and Radu Marinescu. Object-Oriented Metrics in Practice: 6 | Using Software Metrics to Characterize, Evaluate, and Improve the Design 7 | of Object-Oriented Systems. Springer, Berlin, 1 edition, October 2006. Page 80. 8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/GuardDebugLogging.html: -------------------------------------------------------------------------------- 1 | When log messages are composed by concatenating strings, the whole section should be guarded by a isDebugEnabled() check to avoid performance and memory issues. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/GuardLogStatement.html: -------------------------------------------------------------------------------- 1 | Whenever using a log level, one should check if the loglevel is actually enabled, or 2 | otherwise skip the associate String creation and manipulation. Example: 3 |4 | // Add this for performance 5 | if (log.isDebugEnabled() { ... 6 | log.debug("This happens"); 7 |8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/GuardLogStatementJavaUtil.html: -------------------------------------------------------------------------------- 1 | Whenever using a log level, one should check if the loglevel is actually enabled, or 2 | otherwise skip the associate String creation and manipulation. Example: 3 |
4 | // Add this for performance 5 | if (log.isLoggable(Level.FINE)) { ... 6 | log.fine("This happens"); 7 |8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/IdempotentOperations.html: -------------------------------------------------------------------------------- 1 | Avoid idempotent operations - they are have no effect. Example :
int x = 2;
x = x;
2 |
3 | 4 | This rule is deprecated, use {rule:squid:S1656} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/IfElseStmtsMustUseBraces.html: -------------------------------------------------------------------------------- 1 |2 | Avoid using if..else statements without using curly braces. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00121} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/IfStmtsMustUseBraces.html: -------------------------------------------------------------------------------- 1 |2 | Avoid using if statements without using curly braces. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00121} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ImmutableField.html: -------------------------------------------------------------------------------- 1 | Identifies private fields whose values never change once they are initialized either in the declaration of the field or by a constructor. This aids in converting existing classes to immutable classes. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ImportFromSamePackage.html: -------------------------------------------------------------------------------- 1 | No need to import a type that lives in the same package. 2 | 3 |4 | This rule is deprecated, use {rule:squid:UselessImportCheck} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/InefficientEmptyStringCheck.html: -------------------------------------------------------------------------------- 1 | String.trim().length() is an inefficient way to check if a String is really empty, as it creates a new String object just to check its size. Consider creating a static function that loops through a string, checking Character.isWhitespace() on each character and returning false if a non-whitespace character is found. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/InefficientStringBuffering.html: -------------------------------------------------------------------------------- 1 | Avoid concatenating non literals in a StringBuffer constructor or append(). 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/InstantiationToGetClass.html: -------------------------------------------------------------------------------- 1 | Avoid instantiating an object just to call getClass() on it; use the .class public member instead. Example : replace 2 |Class c = new String().getClass();
with Class c = String.class;
3 |
4 | 5 | This rule is deprecated, use {rule:squid:S2133} instead. 6 |
7 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/InsufficientStringBufferDeclaration.html: -------------------------------------------------------------------------------- 1 | Failing to pre-size a StringBuffer properly could cause it to re-size many times during runtime. This rule checks the characters that are actually passed into StringBuffer.append(), but represents a best guess worst case scenario. An empty StringBuffer constructor initializes the object to 16 characters. This default is assumed if the length of the constructor can not be determined. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/IntegerInstantiation.html: -------------------------------------------------------------------------------- 1 | In JDK 1.5, calling new Integer() causes memory allocation. Integer.valueOf() is more memory friendly. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/JumbledIncrementer.html: -------------------------------------------------------------------------------- 1 | Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. 2 |4 | public class JumbledIncrementerRule1 { 5 | public void foo() { 6 | for (int i = 0; i < 10; i++) { 7 | for (int k = 0; k < 20; i++) { 8 | System.out.println("Hello"); 9 | } 10 | } 11 | } 12 | }13 | 14 |
15 | This rule is deprecated, use {rule:squid:ForLoopCounterChangedCheck} instead. 16 |
17 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LawOfDemeter.html: -------------------------------------------------------------------------------- 1 | The Law of Demeter is a simple rule, that says "only talk to friends". It helps to reduce coupling between classes or objects. 2 | See also the references: 3 | Andrew Hunt, David Thomas, and Ward Cunningham. The Pragmatic Programmer. From Journeyman to Master. Addison-Wesley Longman, Amsterdam, October 1999.; 4 | K.J. Lieberherr and I.M. Holland. Assuring good style for object-oriented programs. Software, IEEE, 6(5):38–48, 1989.; 5 | http://www.ccs.neu.edu/home/lieber/LoD.html; 6 | http://en.wikipedia.org/wiki/Law_of_Demeter 7 |Example:
8 |9 | public class Foo { 10 | /** 11 | * This example will result in two violations. 12 | */ 13 | public void example(Bar b) { 14 | // this method call is ok, as b is a parameter of "example" 15 | C c = b.getC(); 16 | 17 | // this method call is a violation, as we are using c, which we got from B. 18 | // We should ask b directly instead, e.g. "b.doItOnC();" 19 | c.doIt(); 20 | 21 | // this is also a violation, just expressed differently as a method chain without temporary variables. 22 | b.getC().doIt(); 23 | 24 | // a constructor call, not a method call. 25 | D d = new D(); 26 | // this method call is ok, because we have create the new instance of D locally. 27 | d.doSomethingElse(); 28 | } 29 | } 30 |31 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LocalHomeNamingConvention.html: -------------------------------------------------------------------------------- 1 | The Local Home interface of a Session EJB should be suffixed by "LocalHome". 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LocalInterfaceSessionNamingConvention.html: -------------------------------------------------------------------------------- 1 | The Local Interface of a Session EJB should be suffixed by "Local". 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LocalVariableCouldBeFinal.html: -------------------------------------------------------------------------------- 1 | A local variable assigned only once can be declared final. Example : 2 |
3 | public class Bar { 4 | public void foo () { 5 | String a = "a"; //if a will not be assigned again it is better to do this: 6 | final String b = "b"; 7 | } 8 | } 9 |10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LoggerIsNotStaticFinal.html: -------------------------------------------------------------------------------- 1 | In most cases, the Logger can be declared static and final. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1312} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LogicInversion.html: -------------------------------------------------------------------------------- 1 | Use opposite operator instead of negating the whole expression with a logic complement operator. Example: 2 |3 | public boolean bar(int a, int b) { 4 | 5 | if (!(a == b)) // use != 6 | return false; 7 | 8 | if (!(a < b)) // use >= 9 | return false; 10 | 11 | return true; 12 | } 13 |14 | 15 |
16 | This rule is deprecated, use {rule:squid:S1940} instead. 17 |
18 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LongInstantiation.html: -------------------------------------------------------------------------------- 1 | In JDK 1.5, calling new Long() causes memory allocation. Long.valueOf() is more memory friendly. Example : 2 |3 | public class Foo { 4 | private Long i = new Long(0); // change to Long i = 5 | Long.valueOf(0); 6 | } 7 |8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LongVariable.html: -------------------------------------------------------------------------------- 1 | Detects when a field, formal or local variable is declared with a long name. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S00117} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LooseCoupling.html: -------------------------------------------------------------------------------- 1 | Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1319} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LooseCouplingWithTypeResolution.html: -------------------------------------------------------------------------------- 1 | Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead Example: 2 |3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | 6 | public class Bar { 7 | 8 | // Use List instead 9 | private ArrayList list = new ArrayList(); 10 | 11 | // Use Set instead 12 | public HashSet getFoo() { 13 | return new HashSet(); 14 | } 15 | } 16 |17 | 18 |
19 | This rule is deprecated, use {rule:squid:S1319} instead. 20 |
21 | 22 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/LoosePackageCoupling.html: -------------------------------------------------------------------------------- 1 | Avoid using classes from the configured package hierarchy outside of the package hierarchy, 2 | except when using one of the configured allowed classes. Example: 3 |4 | package some.package; 5 | 6 | import some.other.package.subpackage.subsubpackage.DontUseThisClass; 7 | 8 | public class Bar { 9 | DontUseThisClass boo = new DontUseThisClass(); 10 | } 11 |12 | 13 |
14 | This rule is deprecated, use {rule:squid:ArchitecturalConstraint} instead. 15 |
16 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MDBAndSessionBeanNamingConvention.html: -------------------------------------------------------------------------------- 1 | The EJB Specification state that any MessageDrivenBean or SessionBean should be suffixed by Bean. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MethodArgumentCouldBeFinal.html: -------------------------------------------------------------------------------- 1 | A method argument that is never assigned can be declared final. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1226} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MethodNamingConventions.html: -------------------------------------------------------------------------------- 1 | Method names should always begin with a lower case character, and should not contain underscores. Example : 2 |3 | public class Foo { 4 | public void fooStuff() { 5 | } 6 | } 7 |8 | 9 |
10 | This rule is deprecated, use {rule:squid:S00100} instead. 11 |
12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MethodReturnsInternalArray.html: -------------------------------------------------------------------------------- 1 | Exposing internal arrays directly allows the user to modify some code that could be critical. It is safer to return a copy of the array. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2384} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MethodWithSameNameAsEnclosingClass.html: -------------------------------------------------------------------------------- 1 | Non-constructor methods should not have the same name as the enclosing class. Example : 2 |3 | public class MyClass { 4 | // this is bad because it is a method 5 | public void MyClass() {} 6 | // this is OK because it is a constructor 7 | public MyClass() {} 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S1223} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MisleadingVariableName.html: -------------------------------------------------------------------------------- 1 | Detects when a non-field has a name starting with 'm_'. This usually indicates a field and thus is confusing. Example : 2 |3 | public class Foo { 4 | private int m_foo; // OK 5 | public void bar(String m_baz) { // Bad 6 | int m_boz = 42; // Bad 7 | } 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S00117} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MisplacedNullCheck.html: -------------------------------------------------------------------------------- 1 | The null check here is misplaced. if the variable is null you'll get a NullPointerException. 2 | Either the check is useless (the variable will never be null) or it's incorrect. 3 |5 | if (object1!=null && object2.equals(object1)) { 6 | ... 7 | } 8 |9 | 10 |
11 | This rule is deprecated, use {rule:squid:S1697} or {rule:squid:S2259} instead. 12 |
13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MissingBreakInSwitch.html: -------------------------------------------------------------------------------- 1 | A switch statement without an enclosed break statement may be a bug. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S128} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MissingSerialVersionUID.html: -------------------------------------------------------------------------------- 1 | Classes that are serializable should provide a serialVersionUID field. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2057} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MissingStaticMethodInNonInstantiatableClass.html: -------------------------------------------------------------------------------- 1 | A class that has private constructors and does not have any static methods or fields cannot be used. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ModifiedCyclomaticComplexity.html: -------------------------------------------------------------------------------- 1 | Complexity directly affects maintenance costs is determined by the number of decision points in a method plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity. Modified complexity treats switch statements as a single decision point. 2 | 3 |4 | This rule is deprecated, use {rule:squid:MethodCyclomaticComplexity} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/MoreThanOneLogger.html: -------------------------------------------------------------------------------- 1 | Normally only one logger is used in each class. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1312} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NPathComplexity.html: -------------------------------------------------------------------------------- 1 | The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity. Example : 2 |3 | public class Foo { 4 | void bar() { 5 | // lots of complicated code 6 | } 7 | } 8 |9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NcssConstructorCount.html: -------------------------------------------------------------------------------- 1 | This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given constructor. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S138} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NcssMethodCount.html: -------------------------------------------------------------------------------- 1 | This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S138} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NcssTypeCount.html: -------------------------------------------------------------------------------- 1 | This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one. 2 | 3 |4 | This rule is deprecated, use {rule:common-java:InsufficientCommentDensity} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NoPackage.html: -------------------------------------------------------------------------------- 1 | Detects when a class or interface does not have a package definition. Example : 2 |3 | // no package declaration 4 | public class ClassInDefaultPackage { 5 | } 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:S1220} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NonCaseLabelInSwitchStatement.html: -------------------------------------------------------------------------------- 1 | A non-case label (e.g. a named break/continue label) was present in a switch statement. This legal, but confusing. It is easy to mix up the case labels and the non-case labels. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1219} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NonStaticInitializer.html: -------------------------------------------------------------------------------- 1 | A nonstatic initializer block will be called any time a constructor is invoked (just prior to invoking the constructor). While this is a valid language construct, it is rarely used and is confusing. Example : 2 |public class MyClass {
// this block gets run before any call to a constructor {
System.out.println("I
3 | am about to construct myself");
}
}
4 |
5 | 6 | This rule is deprecated, use {rule:squid:S1171} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NonThreadSafeSingleton.html: -------------------------------------------------------------------------------- 1 | Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possible by instantiating the object directly. Static singletons are usually not needed as only a single instance exists anyway. Other possible fixes are to synchronize the entire method or to use an initialize-on-demand holder class (do not use the double-check idiom). See Effective Java, item 48. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2444} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/NullAssignment.html: -------------------------------------------------------------------------------- 1 | Assigning a null to a variable (outside of its declaration) is usually bad form. Some times, the assignment is an indication that the programmer doesn't completely understand what is going on in the code. NOTE: This sort of assignment may in rare cases be useful to encourage garbage collection. If that's what you're using it for, by all means, disregard this rule :-) 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/OneDeclarationPerLine.html: -------------------------------------------------------------------------------- 1 | Java allows the use of several variables declaration of the same type on one line. However, it 2 | can lead to quite messy code. This rule looks for several declarations on the same line. Example: 3 |4 | String name; // separate declarations 5 | String lastname; 6 | 7 | String name, lastname; // combined declaration, a violation 8 |9 | 10 |
11 | This rule is deprecated, use {rule:squid:S00122} instead. 12 |
13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/OnlyOneReturn.html: -------------------------------------------------------------------------------- 1 | A method should have only one exit point, and that should be the last statement in the method. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1142} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/OptimizableToArrayCall.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | Calls to a collection’s toArray(E[])
method should specify a target array of zero size. This allows the
4 | JVM to
5 | optimize the memory allocation and copying as much as possible.
6 |
8 | Previous versions of this rule (pre PMD 6.0.0) suggested the opposite, but current JVM implementations 9 | perform always better, when they have full control over the target array. And allocation an array via 10 | reflection is nowadays as fast as the direct allocation. 11 |
12 |13 | See also Arrays of Wisdom of the Ancients 14 |
15 |
16 | Note: If you don’t need an array of the correct type, then the simple toArray()
method without an array
17 | is faster, but
18 | returns only an array of type Object[]
.
19 |
22 | List<Foo> foos = getFoos(); 23 | 24 | // inefficient, the array needs to be zeroed out by the jvm before it is handed over to the toArray method 25 | Foo[] fooArray = foos.toArray(new Foo[foos.size()]); 26 |27 |
29 | List<Foo> foos = getFoos(); 30 | 31 | // much better; this one allows the jvm to allocate an array of the correct size and effectively skip 32 | // the zeroing, since each array element will be overridden anyways 33 | Foo[] fooArray = foos.toArray(new Foo[0]); 34 |35 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/OverrideBothEqualsAndHashcode.html: -------------------------------------------------------------------------------- 1 | Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass. Example : 2 |
3 | // this is bad 4 | public class Bar { 5 | public boolean equals(Object o) { 6 | // do some comparison 7 | } 8 | } 9 | 10 | // and so is this 11 | public class Baz { 12 | public int hashCode() { 13 | // return some hash value 14 | } 15 | } 16 | 17 | // this is OK 18 | public class Foo { 19 | public boolean equals(Object other) { 20 | // do some comparison 21 | } 22 | public int hashCode() { 23 | // return some hash value 24 | } 25 | } 26 |27 | 28 |
29 | This rule is deprecated, use {rule:squid:S1206} instead. 30 |
31 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/PackageCase.html: -------------------------------------------------------------------------------- 1 | Detects when a package definition contains upper case characters. Example : 2 |3 | package com.MyCompany; // <- should be lower case name 4 | public class SomeClass { 5 | } 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:S00120} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/PositionLiteralsFirstInCaseInsensitiveComparisons.html: -------------------------------------------------------------------------------- 1 | Position literals first in comparisons, if the second argument is null then NullPointerExceptions 2 | can be avoided, they will just return false. Example: 3 |4 | class Foo { 5 | boolean bar(String x) { 6 | return x.equalsIgnoreCase("2"); // should be "2".equalsIgnoreCase(x) 7 | } 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S1132} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/PositionLiteralsFirstInComparisons.html: -------------------------------------------------------------------------------- 1 | Position literals first in String comparisons - that way if the String is null you won't get a NullPointerException, it'll just return false. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1132} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/PrematureDeclaration.html: -------------------------------------------------------------------------------- 1 | Checks for variables that are defined before they might be used. A reference is deemed to be premature if it is created right before a block of code that doesn't use it that also has the ability to return or throw an exception. Example: 2 |3 | public int getLength(String[] strings) { 4 | 5 | int length = 0; // declared prematurely 6 | 7 | if (strings == null || strings.length == 0) return 0; 8 | 9 | for (String str : strings) { 10 | length += str.length(); 11 | } 12 | 13 | return length; 14 | } 15 |16 | 17 |
18 | This rule is deprecated, use {rule:squid:S1941} instead. 19 |
20 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/PreserveStackTrace.html: -------------------------------------------------------------------------------- 1 | Throwing a new exception from a catch block without passing the original exception into the new Exception will cause the true stack trace to be lost, and can make it difficult to debug effectively. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1166} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ProperCloneImplementation.html: -------------------------------------------------------------------------------- 1 | Object clone() should be implemented with super.clone(). Example : 2 |3 | class Foo{ 4 | public Object clone(){ 5 | return new Foo(); // This is bad 6 | } 7 | } 8 |9 | 10 |
11 | This rule is deprecated, use {rule:squid:S1182} instead. 12 |
13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ProperLogger.html: -------------------------------------------------------------------------------- 1 | Logger should normally be defined private static final and have the correct class. Private final Log log; is also allowed for rare cases when loggers need to be passed around, but the logger needs to be passed into the constructor. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1312} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/RedundantFieldInitializer.html: -------------------------------------------------------------------------------- 1 | Java will initialize fields with known default values so any explicit initialization of those same defaults 2 | is redundant and results in a larger class file (approximately three additional bytecode instructions per field). Example: 3 |4 | public class C { 5 | boolean b = false; // examples of redundant initializers 6 | byte by = 0; 7 | short s = 0; 8 | char c = 0; 9 | int i = 0; 10 | long l = 0; 11 | 12 | float f = .0f; // all possible float literals 13 | doable d = 0d; // all possible double literals 14 | Object o = null; 15 | 16 | MyClass mca[] = null; 17 | int i1 = 0, ia1[] = null; 18 | 19 | class Nested { 20 | boolean b = false; 21 | } 22 | } 23 |24 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/RemoteInterfaceNamingConvention.html: -------------------------------------------------------------------------------- 1 | Remote Interface of a Session EJB should NOT be suffixed. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/RemoteSessionInterfaceNamingConvention.html: -------------------------------------------------------------------------------- 1 | Remote Home interface of a Session EJB should be suffixed by "Home". 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ReplaceEnumerationWithIterator.html: -------------------------------------------------------------------------------- 1 | Consider replacing this Enumeration with the newer java.util.Iterator 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1150} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ReplaceHashtableWithMap.html: -------------------------------------------------------------------------------- 1 | Consider replacing this Hashtable with the newer java.util.Map 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1149} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ReplaceVectorWithList.html: -------------------------------------------------------------------------------- 1 | Consider replacing Vector usages with the newer java.util.ArrayList if expensive threadsafe operation is not required. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1149} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ReturnEmptyArrayRatherThanNull.html: -------------------------------------------------------------------------------- 1 | For any method that returns an array, it's a better behavior to return an empty array rather than a null reference. Example : 2 |3 | public class Example 4 | { 5 | // Not a good idea... 6 | public int []badBehavior() 7 | { 8 | // ... 9 | return null; 10 | } 11 | 12 | // Good behavior 13 | public String[] bonnePratique() 14 | { 15 | //... 16 | return new String[0]; 17 | } 18 | } 19 |20 | 21 |
22 | This rule is deprecated, use {rule:squid:S1168} instead. 23 |
24 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ReturnFromFinallyBlock.html: -------------------------------------------------------------------------------- 1 | Avoid returning from a finally block - this can discard exceptions. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1143} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ShortClassName.html: -------------------------------------------------------------------------------- 1 | Classnames with fewer than five characters are not recommended. Example: 2 |3 | public class Foo { 4 | } 5 |6 | 7 |
8 | This rule is deprecated, use {rule:squid:S00101} instead. 9 |
10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ShortInstantiation.html: -------------------------------------------------------------------------------- 1 | In JDK 1.5, calling new Short() causes memory allocation. Short.valueOf() is more memory friendly. Example : 2 |3 | public class Foo { 4 | private Short i = new Short(0); // change to Short i = 5 | Short.valueOf(0); 6 | } 7 |8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ShortMethodName.html: -------------------------------------------------------------------------------- 1 | Detects when very short method names are used. Example : 2 |
3 | public class ShortMethod { 4 | public void a( int i ) { // Violation 5 | } 6 | } 7 |8 | 9 |
10 | This rule is deprecated, use {rule:squid:S00100} instead. 11 |
12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/ShortVariable.html: -------------------------------------------------------------------------------- 1 | Detects when a field, local, or parameter has a very short name. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00117} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SignatureDeclareThrowsException.html: -------------------------------------------------------------------------------- 1 | It is unclear which exceptions that can be thrown from the methods. It might be difficult to document and understand the vague interfaces. Use either a class derived from RuntimeException or a checked exception. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00112} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SignatureDeclareThrowsExceptionWithTypeResolution.html: -------------------------------------------------------------------------------- 1 | It is unclear which exceptions that can be thrown from the methods. 2 | It might be difficult to document and understand the vague interfaces. 3 | Use either a class derived from RuntimeException or a checked exception. 4 | 5 | JUnit classes are excluded. Example: 6 |7 | public void methodThrowingException() throws Exception { 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S00112} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimpleDateFormatNeedsLocale.html: -------------------------------------------------------------------------------- 1 | Be sure to specify a Locale when creating a new instance of SimpleDateFormat. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimplifiedTernary.html: -------------------------------------------------------------------------------- 1 |2 | Look for ternary operators with the form condition ? literalBoolean : foo or condition ? foo : literalBoolean. 3 |
4 | 5 |Examples:
6 |7 | public class Foo { 8 | public boolean test() { 9 | return condition ? true : something(); // can be as simple as return condition || something(); 10 | } 11 | 12 | public void test2() { 13 | final boolean value = condition ? false : something(); // can be as simple as value = !condition && something(); 14 | } 15 | 16 | public boolean test3() { 17 | return condition ? something() : true; // can be as simple as return !condition || something(); 18 | } 19 | 20 | public void test4() { 21 | final boolean otherValue = condition ? something() : false; // can be as simple as condition && something(); 22 | } 23 | } 24 |25 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimplifyBooleanExpressions.html: -------------------------------------------------------------------------------- 1 | Avoid unnecessary comparisons in boolean expressions - this complicates simple code. Example : 2 |
3 | public class Bar { 4 | // can be simplified to 5 | // bar = isFoo(); 6 | private boolean bar = (isFoo() == true); 7 | 8 | public isFoo() { return false;} 9 | } 10 |11 | 12 |
13 | This rule is deprecated, use {rule:squid:S1125} instead. 14 |
15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimplifyBooleanReturns.html: -------------------------------------------------------------------------------- 1 | Avoid unnecessary if..then..else statements when returning a boolean. Example : 2 |3 | public class Foo { 4 | private int bar =2; 5 | public boolean isBarEqualsTo(int x) { 6 | // this bit of code 7 | if (bar == x) { 8 | return true; 9 | } else { 10 | return false; 11 | } 12 | // can be replaced with a simple 13 | // return bar == x; 14 | } 15 | } 16 |17 | 18 |
19 | This rule is deprecated, use {rule:squid:S1126} instead. 20 |
21 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimplifyConditional.html: -------------------------------------------------------------------------------- 1 | No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SimplifyStartsWith.html: -------------------------------------------------------------------------------- 1 | Since it passes in a literal of length 1, this call to String.startsWith can be rewritten using String.charAt(0) to save some time. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SingleMethodSingleton.html: -------------------------------------------------------------------------------- 1 |2 | Some classes contain overloaded getInstance. The problem with overloaded getInstance methods is that the instance 3 | created using the overloaded method is not cached and so, for each call and new objects will be created for every 4 | invocation. 5 |
6 | 7 |Examples:
8 |9 | public class Singleton { 10 | private static Singleton singleton = new Singleton( ); 11 | 12 | private Singleton() { } 13 | 14 | public static Singleton getInstance( ) { 15 | return singleton; 16 | } 17 | 18 | public static Singleton getInstance(Object obj) { 19 | Singleton singleton = (Singleton) obj; 20 | return singleton; //violation 21 | } 22 | } 23 |24 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SingletonClassReturningNewInstance.html: -------------------------------------------------------------------------------- 1 |
2 | Some classes contain overloaded getInstance. The problem with overloaded getInstance methods is that the instance 3 | created using the overloaded method is not cached and so, for each call and new objects will be created for every 4 | invocation. 5 |
6 | 7 |Examples:
8 |9 | class Singleton { 10 | private static Singleton instance = null; 11 | 12 | public static Singleton getInstance() { 13 | synchronized(Singleton.class) { 14 | return new Singleton(); 15 | } 16 | } 17 | } 18 |19 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SingularField.html: -------------------------------------------------------------------------------- 1 | A field that's only used by one method could perhaps be replaced by a local variable. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/StaticEJBFieldShouldBeFinal.html: -------------------------------------------------------------------------------- 1 | According to the J2EE specification (p.494), an EJB should not have any static fields with write access. However, static read only fields are allowed. This ensures proper behavior especially when instances are distributed by the container on several JREs. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/StdCyclomaticComplexity.html: -------------------------------------------------------------------------------- 1 | Complexity directly affects maintenance costs is determined by the number of decision points in a method plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:MethodCyclomaticComplexity} or {rule:squid:ClassCyclomaticComplexity} 5 | instead. 6 |
7 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/StringBufferInstantiationWithChar.html: -------------------------------------------------------------------------------- 1 | StringBuffer sb = new StringBuffer('c'); The char will be converted into int to intialize StringBuffer size. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1317} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/StringInstantiation.html: -------------------------------------------------------------------------------- 1 | Avoid instantiating String objects; this is usually unnecessary. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/StringToString.html: -------------------------------------------------------------------------------- 1 | Avoid calling toString() on String objects; this is unnecessary. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1858} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SuspiciousConstantFieldName.html: -------------------------------------------------------------------------------- 1 | A field name is all in uppercase characters, which in Sun's Java naming conventions indicate a constant. However, the field is not final. Example : 2 |3 | public class Foo { 4 | // this is bad, since someone could accidentally 5 | // do PI = 2.71828; which is actualy e 6 | // final double PI = 3.16; is ok 7 | double PI = 3.16; 8 | } 9 |10 | 11 |
12 | This rule is deprecated, use {rule:squid:S00116} instead. 13 |
14 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SuspiciousEqualsMethodName.html: -------------------------------------------------------------------------------- 1 | The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method. Example : 2 |3 | public class Foo { 4 | public int equals(Object o) { 5 | // oops, this probably was supposed to be boolean equals 6 | } 7 | public boolean equals(String s) { 8 | // oops, this probably was supposed to be equals(Object) 9 | } 10 | } 11 |12 | 13 |
14 | This rule is deprecated, use {rule:squid:S1201} instead. 15 |
16 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SuspiciousHashcodeMethodName.html: -------------------------------------------------------------------------------- 1 | The method name and return type are suspiciously close to hashCode(), which may mean you are intending to override the hashCode() method. Example : 2 |3 | public class Foo { 4 | public int hashcode() { 5 | // oops, this probably was supposed to be hashCode 6 | } 7 | }8 | 9 |
10 | This rule is deprecated, use {rule:squid:S1221} instead. 11 |
12 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SuspiciousOctalEscape.html: -------------------------------------------------------------------------------- 1 | A suspicious octal escape sequence was found inside a String literal. The Java language specification (section 3.10.6) says an octal escape sequence inside a literal String shall consist of a backslash followed by: OctalDigit | OctalDigit OctalDigit | ZeroToThree OctalDigit OctalDigit Any octal escape sequence followed by non-octal digits can be confusing, e.g. "\038" is interpreted as the octal escape sequence "\03" followed by the literal character 8. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SwitchDensity.html: -------------------------------------------------------------------------------- 1 | A high ratio of statements to labels in a switch statement implies that the switch statement is doing too much work. Consider moving the statements into new methods, or creating subclasses based on the switch variable. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1151} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SwitchStmtsShouldHaveDefault.html: -------------------------------------------------------------------------------- 1 | Switch statements should have a default label. Example : 2 |3 | public class Foo { 4 | public void bar() { 5 | int x = 2; 6 | switch (x) { 7 | case 2: int j = 8; 8 | } 9 | } 10 | } 11 |12 | 13 |
14 | This rule is deprecated, use {rule:squid:SwitchLastCaseIsDefaultCheck} instead. 15 |
16 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/SystemPrintln.html: -------------------------------------------------------------------------------- 1 | System.(out|err).print is used, consider using a logger. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S106} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/TooFewBranchesForASwitchStatement.html: -------------------------------------------------------------------------------- 1 | Swith are designed complex branches, and allow branches to share treatement. Using a switch for only a few branches is ill advised, as switches are not as easy to understand as if. In this case, it's most likely is a good idea to use a if statement instead, at least to increase code readability. Example : 2 |3 | // With a minimumNumberCaseForASwitch of 3 4 | public class Foo { 5 | public void bar() { 6 | switch (condition) { 7 | case ONE: 8 | instruction; 9 | break; 10 | default: 11 | break; // not enough for a 'switch' stmt, 12 | // a simple 'if' stmt would have been more appropriate 13 | } 14 | } 15 | } 16 |17 | 18 |
19 | This rule is deprecated, use {rule:squid:S1301} instead. 20 |
21 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/TooManyFields.html: -------------------------------------------------------------------------------- 1 | Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/TooManyMethods.html: -------------------------------------------------------------------------------- 1 | A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1448} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/TooManyStaticImports.html: -------------------------------------------------------------------------------- 1 | If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from (Sun 1.5 Language Guide). 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UncommentedEmptyConstructor.html: -------------------------------------------------------------------------------- 1 | Uncommented Empty Constructor finds instances where a constructor does not contain statements, but there is no comment. By explicitly commenting empty constructors it is easier to distinguish between intentional (commented) and unintentional empty constructors. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2094} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UncommentedEmptyMethodBody.html: -------------------------------------------------------------------------------- 1 |Uncommented Empty Method finds instances where a method does not contain statements, but there is no comment. By 2 | explicitly commenting empty methods it is easier to distinguish between intentional (commented) and unintentional 3 | empty methods.
4 | 5 |6 | This rule is deprecated, use {rule:squid:S1186} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnconditionalIfStatement.html: -------------------------------------------------------------------------------- 1 | Do not use if statements that are always true or always false. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2583} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryCaseChange.html: -------------------------------------------------------------------------------- 1 | Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals() 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1157} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryConstructor.html: -------------------------------------------------------------------------------- 1 | This rule detects when a constructor is not necessary; i.e., when there's only one constructor, it's public, has an empty body, and takes no arguments. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1186} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryConversionTemporary.html: -------------------------------------------------------------------------------- 1 | Avoid unnecessary temporaries when converting primitives to Strings 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1158} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryFinalModifier.html: -------------------------------------------------------------------------------- 1 | When a class has the final modifier, all the methods are automatically final. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryFullyQualifiedName.html: -------------------------------------------------------------------------------- 1 | Import statements allow the use of non-fully qualified names. The use of a fully qualified name 2 | which is covered by an import statement is redundant. Consider using the non-fully qualified name. Example: 3 |4 | import java.util.List; 5 | 6 | public class Foo { 7 | private java.util.List list1; // Unnecessary FQN 8 | private List list2; // More appropriate given import of 'java.util.List' 9 | } 10 |11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryLocalBeforeReturn.html: -------------------------------------------------------------------------------- 1 | Avoid unnecessarily creating local variables 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1488} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryParentheses.html: -------------------------------------------------------------------------------- 1 | Sometimes expressions are wrapped in unnecessary parentheses, making them look like a function call. Example : 2 |3 | public class Foo { 4 | boolean bar() { 5 | return (true); 6 | } 7 | } 8 |9 | 10 |
11 | This rule is deprecated, use {rule:squid:UselessParenthesesCheck} instead. 12 |
13 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryReturn.html: -------------------------------------------------------------------------------- 1 | Avoid unnecessary return statements 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnnecessaryWrapperObjectCreation.html: -------------------------------------------------------------------------------- 1 | Parsing method should be called directy instead. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1158} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnsynchronizedStaticDateFormatter.html: -------------------------------------------------------------------------------- 1 | SimpleDateFormat is not synchronized. Sun recomends separate format instances for each thread. If multiple threads must access a static formatter, the formatter must be synchronized either on method or block level. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2156} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedFormalParameter.html: -------------------------------------------------------------------------------- 1 |Avoid passing parameters to methods or constructors and then not using those parameters.
2 | 3 |4 | This rule is deprecated, use {rule:squid:S1172} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedImports.html: -------------------------------------------------------------------------------- 1 | Avoid unused import statements. Example : 2 |3 | // this is bad 4 | import java.io.File; 5 | public class Foo {} 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:UselessImportCheck} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedImportsWithTypeResolution.html: -------------------------------------------------------------------------------- 1 | Avoid unused import statements. This rule will find unused on demand imports, i.e. import com.foo.*. Example: 2 |3 | import java.io.*; // not referenced or required 4 | 5 | public class Foo {} 6 |7 | 8 |
9 | This rule is deprecated, use {rule:squid:UselessImportCheck} instead. 10 |
11 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedLocalVariable.html: -------------------------------------------------------------------------------- 1 | Detects when a local variable is declared and/or assigned, but not used. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1481} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedModifier.html: -------------------------------------------------------------------------------- 1 | Fields in interfaces are automatically public static final, and methods are public abstract. Classes or interfaces nested in an interface are automatically public and static (all nested interfaces are automatically static). For historical reasons, modifiers which are implied by the context are accepted by the compiler, but are superfluous. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedNullCheckInEquals.html: -------------------------------------------------------------------------------- 1 | After checking an object reference for null, you should invoke equals() on that object rather than passing it to another object's equals() method. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedPrivateField.html: -------------------------------------------------------------------------------- 1 | Detects when a private field is declared and/or assigned a value, but not used. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1068} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UnusedPrivateMethod.html: -------------------------------------------------------------------------------- 1 |2 | Unused Private Method detects when a private method is declared but is unused. This PMD rule should be switched off 3 | and replaced by its equivalent from Squid that is more effective : it generates less false-positives and detects more 4 | dead code. 5 |
6 | 7 |8 | This rule is deprecated, use {rule:squid:UnusedPrivateMethod} instead. 9 |
10 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseArrayListInsteadOfVector.html: -------------------------------------------------------------------------------- 1 | ArrayList is a much better Collection implementation than Vector. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1149} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseArraysAsList.html: -------------------------------------------------------------------------------- 1 | The class java.util.Arrays has a asList method that should be use when you want to create a new List from an array of objects. It is faster than executing a loop to cpy all the elements of the array one by one 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseCollectionIsEmpty.html: -------------------------------------------------------------------------------- 1 | The isEmpty() method on java.util.Collection is provided to see if a collection has any elements. Comparing the value of size() to 0 merely duplicates existing behavior. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1155} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseConcurrentHashMap.html: -------------------------------------------------------------------------------- 1 | Since Java5 brought a new implementation of the Map interface, specially designed for concurrent application. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseCorrectExceptionLogging.html: -------------------------------------------------------------------------------- 1 | To make sure the full stacktrace is printed out, use the logging statement with 2 arguments: a String and a Throwable. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S1166} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseEqualsToCompareStrings.html: -------------------------------------------------------------------------------- 1 | Using "==" or "!=" to compare strings only works if intern version is used on both sides. 2 | 3 |4 | This rule is deprecated, use {rule:squid:StringEqualityComparisonCheck} or {rule:squid:S1698} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseIndexOfChar.html: -------------------------------------------------------------------------------- 1 | Use String.indexOf(char) when checking for the index of a single character; it executes faster. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseLocaleWithCaseConversions.html: -------------------------------------------------------------------------------- 1 | When doing a String.toLowerCase()/toUpperCase() call, use a Locale. This avoids problems with certain locales, i.e. Turkish. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseNotifyAllInsteadOfNotify.html: -------------------------------------------------------------------------------- 1 | Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus it's usually safer to call notifyAll() instead. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S2446} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseObjectForClearerAPI.html: -------------------------------------------------------------------------------- 1 | When you write a public method, you should be thinking in terms of an API. If your method is public, it means other class 2 | will use it, therefore, you want (or need) to offer a comprehensive and evolutive API. If you pass a lot of information 3 | as a simple series of Strings, you may think of using an Object to represent all those information. You'll get a simplier 4 | API (such as doWork(Workload workload), rather than a tedious series of Strings) and more importantly, if you need at some 5 | point to pass extra data, you'll be able to do so by simply modifying or extending Workload without any modification to 6 | your API. Example: 7 |8 | public class MyClass { 9 | public void connect(String username, 10 | String pssd, 11 | String databaseName, 12 | String databaseAdress) 13 | // Instead of those parameters object 14 | // would ensure a cleaner API and permit 15 | // to add extra data transparently (no code change): 16 | // void connect(UserData data); 17 | { 18 | 19 | } 20 | } 21 |22 | 23 |
24 | This rule is deprecated, use {rule:squid:S00107} instead. 25 |
26 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseProperClassLoader.html: -------------------------------------------------------------------------------- 1 | In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseStringBufferForStringAppends.html: -------------------------------------------------------------------------------- 1 | Finds usages of += for appending strings. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseStringBufferLength.html: -------------------------------------------------------------------------------- 1 | Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals() or StringBuffer.toString().length() ==. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseUtilityClass.html: -------------------------------------------------------------------------------- 1 | For classes that only have static methods, consider making them utility classes. 2 | Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. 3 | Also, if you want this class to be a utility class, remember to add a private constructor to prevent instantiation. 4 | (Note, that this use was known before PMD 5.1.0 as UseSingleton). 5 | 6 |7 | This rule is deprecated, use {rule:squid:S1118} instead. 8 |
9 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UseVarargs.html: -------------------------------------------------------------------------------- 1 | Java 5 introduced the varargs parameter declaration for methods and constructors. This syntactic 2 | sugar provides flexibility for users of these methods and constructors, allowing them to avoid 3 | having to deal with the creation of an array. Example: 4 |5 | public class Foo { 6 | public void foo(String s, Object[] args) { 7 | // Do something here... 8 | } 9 | 10 | public void bar(String s, Object... args) { 11 | // Ahh, varargs tastes much better... 12 | } 13 | } 14 |15 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UselessOperationOnImmutable.html: -------------------------------------------------------------------------------- 1 | An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself. The result of the operation is a new object. Therefore, ignoring the operation result is an error. 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UselessOverridingMethod.html: -------------------------------------------------------------------------------- 1 | The overriding method merely calls the same method defined in a superclass 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1185} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UselessParentheses.html: -------------------------------------------------------------------------------- 1 | Useless parentheses should be removed. Example: 2 |3 | public class Foo { 4 | 5 | private int _bar1; 6 | private Integer _bar2; 7 | 8 | public void setBar(int n) { 9 | _bar1 = Integer.valueOf((n)); // here 10 | _bar2 = (n); // and here 11 | } 12 | 13 | } 14 |15 | 16 |
17 | This rule is deprecated, use {rule:squid:UselessParenthesesCheck} instead. 18 |
19 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UselessQualifiedThis.html: -------------------------------------------------------------------------------- 1 |Look for qualified this usages in the same class.
2 | 3 |Examples:
4 | 5 |6 | public class Foo { 7 | final Foo otherFoo = Foo.this; // use "this" directly 8 | 9 | public void doSomething() { 10 | final Foo anotherFoo = Foo.this; // use "this" directly 11 | } 12 | 13 | private ActionListener returnListener() { 14 | return new ActionListener() { 15 | @Override 16 | public void actionPerformed(ActionEvent e) { 17 | doSomethingWithQualifiedThis(Foo.this); // This is fine 18 | } 19 | }; 20 | } 21 | 22 | private class Foo3 { 23 | final Foo myFoo = Foo.this; // This is fine 24 | } 25 | 26 | private class Foo2 { 27 | final Foo2 myFoo2 = Foo2.this; // Use "this" direclty 28 | } 29 | } 30 |31 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/UselessStringValueOf.html: -------------------------------------------------------------------------------- 1 | No need to call String.valueOf to append to a string; just use the valueOf() argument directly. 2 | 3 |
4 | This rule is deprecated, use {rule:squid:S1153} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/VariableNamingConventions.html: -------------------------------------------------------------------------------- 1 | A variable naming conventions rule - customize this to your liking. Currently, it checks for final variables that should be fully capitalized and non-final variables that should not include underscores. 2 | 3 |4 | This rule is deprecated, use {rule:squid:S00115} and {rule:squid:S00116} instead. 5 |
6 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/WhileLoopsMustUseBraces.html: -------------------------------------------------------------------------------- 1 |2 | Avoid using 'while' statements without using curly braces. 3 |
4 | 5 |6 | This rule is deprecated, use {rule:squid:S00121} instead. 7 |
8 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd/XPathRule.html: -------------------------------------------------------------------------------- 1 | PMD provides a very handy method for creating new rules by writing an XPath query. When the XPath query finds a match, a violation is created. 2 | Let's take a simple example: assume we have a Factory class that must be always declared final. 3 | We'd like to report a violation each time a declaration of Factory is not declared final. Consider the following class: 4 |5 | public class a { 6 | Factory f1; 7 | 8 | void myMethod() { 9 | Factory f2; 10 | int a; 11 | } 12 | } 13 |14 | The following expression does the magic we need: 15 |
16 | //VariableDeclarator 17 | [../Type/ReferenceType/ClassOrInterfaceType 18 | [@Image = 'Factory'] and ..[@Final='false']] 19 |20 | See the XPath rule 21 | tutorial for more information. 22 | 23 |
24 | This rule is deprecated, please see the documentation on Extending 25 | Coding Rules. 26 |
27 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdConstantsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube PMD Plugin 3 | * Copyright (C) 2012-2019 SonarSource SA 4 | * mailto:info AT sonarsource DOT com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.pmd; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.assertj.core.api.Assertions.assertThat; 25 | 26 | class PmdConstantsTest { 27 | 28 | @Test 29 | void checkDefinedKeys() { 30 | assertThat(PmdConstants.PLUGIN_NAME).isEqualTo("PMD"); 31 | assertThat(PmdConstants.PLUGIN_KEY).isEqualTo("pmd"); 32 | assertThat(PmdConstants.REPOSITORY_KEY).isEqualTo("pmd"); 33 | assertThat(PmdConstants.REPOSITORY_NAME).isEqualTo("PMD"); 34 | assertThat(PmdConstants.TEST_REPOSITORY_KEY).isEqualTo("pmd-unit-tests"); 35 | assertThat(PmdConstants.TEST_REPOSITORY_NAME).isEqualTo("PMD Unit Tests"); 36 | assertThat(PmdConstants.XPATH_CLASS).isEqualTo("net.sourceforge.pmd.lang.rule.XPathRule"); 37 | assertThat(PmdConstants.XPATH_EXPRESSION_PARAM).isEqualTo("xpath"); 38 | assertThat(PmdConstants.XPATH_MESSAGE_PARAM).isEqualTo("message"); 39 | assertThat(PmdConstants.JAVA_SOURCE_VERSION).isEqualTo("sonar.java.source"); 40 | assertThat(PmdConstants.JAVA_SOURCE_VERSION_DEFAULT_VALUE).isEqualTo("1.6"); 41 | assertThat(PmdConstants.LANGUAGE_KEY).isEqualTo("java"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdTestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SonarQube PMD Plugin 3 | * Copyright (C) 2012-2019 SonarSource SA 4 | * mailto:info AT sonarsource DOT com 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 3 of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program; if not, write to the Free Software Foundation, 18 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | package org.sonar.plugins.pmd; 21 | 22 | import java.io.IOException; 23 | import java.net.URI; 24 | import java.net.URISyntaxException; 25 | import java.nio.charset.StandardCharsets; 26 | import java.nio.file.Files; 27 | import java.nio.file.Paths; 28 | 29 | public class PmdTestUtils { 30 | 31 | public static String getResourceContent(String path) { 32 | 33 | try { 34 | final URI resource = PmdTestUtils.class.getResource(path).toURI(); 35 | return new String(Files.readAllBytes(Paths.get(resource)), StandardCharsets.UTF_8); 36 | } catch (URISyntaxException e) { 37 | throw new IllegalArgumentException("Given Path " + path + " can not be resolved to a valid URI.", e); 38 | } catch (IOException e) { 39 | throw new IllegalStateException("Requested Path " + path + " seems to not be available.", e); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/test/resources/org/sonar/l10n/languageKey/rules/repoKey/ruleWithExternalInfo.html: -------------------------------------------------------------------------------- 1 | description for ruleWithExternalInfo 2 | -------------------------------------------------------------------------------- /sonar-pmd-plugin/src/test/resources/org/sonar/plugins/pmd/complex-with-unknown-nodes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |