diff --git a/.pmd b/.pmd index 07fc23d..35b5d07 100644 --- a/.pmd +++ b/.pmd @@ -1,1595 +1,8 @@ Java Main Sources - false - - .* - - - .*\.java - - - - AbstractClassWithoutAbstractMethod - Best Practices - - - AccessorClassGeneration - Best Practices - - - AccessorMethodGeneration - Best Practices - - - AmbiguousResolution - Best Practices - - - ApexAssertionsShouldIncludeMessage - Best Practices - - - ApexUnitTestClassShouldHaveAsserts - Best Practices - - - ApexUnitTestClassShouldHaveRunAs - Best Practices - - - ApexUnitTestMethodShouldHaveIsTestAnnotation - Best Practices - - - ApexUnitTestShouldNotUseSeeAllDataTrue - Best Practices - - - ArrayIsStoredDirectly - Best Practices - - - AvoidGlobalModifier - Best Practices - - - AvoidInlineStyles - Best Practices - - - AvoidLogicInTrigger - Best Practices - - - AvoidMessageDigestField - Best Practices - - - AvoidPrintStackTrace - Best Practices - - - AvoidReassigningCatchVariables - Best Practices - - - AvoidReassigningLoopVariables - Best Practices - - - AvoidReassigningParameters - Best Practices - - - AvoidStringBufferField - Best Practices - - - AvoidUsingHardCodedIP - Best Practices - - - AvoidWithStatement - Best Practices - - - CheckResultSet - Best Practices - - - ClassStartNameEqualsEndName - Best Practices - - - ConnectUsingNonConnector - Best Practices - - - ConsistentReturn - Best Practices - - - ConstantsInInterface - Best Practices - - - DebugsShouldUseLoggingLevel - Best Practices - - - DefaultLabelNotLastInSwitch - Best Practices - - - DontNestJsfInJstlIteration - Best Practices - - - DoubleBraceInitialization - Best Practices - - - ExhaustiveSwitchHasDefault - Best Practices - - - ForLoopCanBeForeach - Best Practices - - - ForLoopVariableCount - Best Practices - - - FunctionNameTooShort - Best Practices - - - GlobalVariable - Best Practices - - - GuardLogStatement - Best Practices - - - ImplicitFunctionalInterface - Best Practices - - - JUnit4SuitesShouldUseSuiteAnnotation - Best Practices - - - JUnit5TestShouldBePackagePrivate - Best Practices - - - JUnitUseExpected - Best Practices - - - LiteralsFirstInComparisons - Best Practices - - - LooseCoupling - Best Practices - - - MethodReturnsInternalArray - Best Practices - - - MissingEncoding - Best Practices - - - MissingOverride - Best Practices - - - NoClassAttribute - Best Practices - - - NoHtmlComments - Best Practices - - - NoJspForward - Best Practices - - - NonExhaustiveSwitch - Best Practices - - - PreserveStackTrace - Best Practices - - - PrimitiveWrapperInstantiation - Best Practices - - - ProhibitedInterfaceBuilder - Best Practices - - - QueueableWithoutFinalizer - Best Practices - - - ReplaceEnumerationWithIterator - Best Practices - - - ReplaceHashtableWithMap - Best Practices - - - ReplaceVectorWithList - Best Practices - - - ScopeForInVariable - Best Practices - - - SimplifiableTestAssertion - Best Practices - - - SystemPrintln - Best Practices - - - TomKytesDespair - Best Practices - - - UnavailableFunction - Best Practices - - - UnitTestAssertionsShouldIncludeMessage - Best Practices - - - UnitTestContainsTooManyAsserts - Best Practices - - - UnitTestShouldIncludeAssert - Best Practices - - - UnitTestShouldUseAfterAnnotation - Best Practices - - - UnitTestShouldUseBeforeAnnotation - Best Practices - - - UnitTestShouldUseTestAnnotation - Best Practices - - - UnnecessaryTypeAttribute - Best Practices - - - UnnecessaryVarargsArrayCreation - Best Practices - - - UnnecessaryWarningSuppression - Best Practices - - - UnusedAssignment - Best Practices - - - UnusedFormalParameter - Best Practices - - - UnusedLocalVariable - Best Practices - - - UnusedMacroParameter - Best Practices - - - UnusedPrivateField - Best Practices - - - UnusedPrivateMethod - Best Practices - - - UseAltAttributeForImages - Best Practices - - - UseBaseWithParseInt - Best Practices - - - UseCollectionIsEmpty - Best Practices - - - UseEnumCollections - Best Practices - - - UseStandardCharsets - Best Practices - - - UseTryWithResources - Best Practices - - - UseVarargs - Best Practices - - - WhileLoopWithLiteralBoolean - Best Practices - - - AssignmentInOperand - Code Style - - - AtLeastOneConstructor - Code Style - - - AvoidDollarSigns - Code Style - - - AvoidProtectedFieldInFinalClass - Code Style - - - AvoidProtectedMethodInFinalClassNotExtending - Code Style - - - AvoidTabCharacter - Code Style - - - AvoidUsingNativeCode - Code Style - - - BooleanGetMethodName - Code Style - - - CallSuperInConstructor - Code Style - - - ClassNamingConventions - Code Style - - - CodeFormat - Code Style - - - CommentDefaultAccessModifier - Code Style - - - ConfusingTernary - Code Style - - - ControlStatementBraces - Code Style - - - DuplicateJspImports - Code Style - - - EmptyControlStatement - Code Style - - - EmptyMethodInAbstractClassShouldBeAbstract - Code Style - - - ExtendsObject - Code Style - - - FieldDeclarationsShouldBeAtStart - Code Style - - - FieldDeclarationsShouldBeAtStartOfClass - Code Style - - - FieldNamingConventions - Code Style - - - FinalParameterInAbstractMethod - Code Style - - - ForLoopNaming - Code Style - - - ForLoopShouldBeWhileLoop - Code Style - - - ForLoopsMustUseBraces - Code Style - - - FormalParameterNamingConventions - Code Style - - - GenericsNaming - Code Style - - - IdenticalCatchBranches - Code Style - - - IfElseStmtsMustUseBraces - Code Style - - - IfStmtsMustUseBraces - Code Style - - - LambdaCanBeMethodReference - Code Style - - - LineLength - Code Style - - - LinguisticNaming - Code Style - - - LocalHomeNamingConvention - Code Style - - - LocalInterfaceSessionNamingConvention - Code Style - - - LocalVariableCouldBeFinal - Code Style - - - LocalVariableNamingConventions - Code Style - - - LongVariable - Code Style - - - MDBAndSessionBeanNamingConvention - Code Style - - - MethodArgumentCouldBeFinal - Code Style - - - MethodNamingConventions - Code Style - - - MisplacedPragma - Code Style - - - NoElseReturn - Code Style - - - NoPackage - Code Style - - - OneDeclarationPerLine - Code Style - - - OnlyOneReturn - Code Style - - - PackageCase - Code Style - - - PrematureDeclaration - Code Style - - - PropertyNamingConventions - Code Style - - - RemoteInterfaceNamingConvention - Code Style - - - RemoteSessionInterfaceNamingConvention - Code Style - - - ShortClassName - Code Style - - - ShortMethodName - Code Style - - - ShortVariable - Code Style - - - TooManyStaticImports - Code Style - - - UnnecessaryAnnotationValueElement - Code Style - - - UnnecessaryBlock - Code Style - - - UnnecessaryBoxing - Code Style - - - UnnecessaryCast - Code Style - - - UnnecessaryConstructor - Code Style - - - UnnecessaryFullyQualifiedName - Code Style - - - UnnecessaryImport - Code Style - - - UnnecessaryLocalBeforeReturn - Code Style - - - UnnecessaryModifier - Code Style - - - UnnecessaryParentheses - Code Style - - - UnnecessaryReturn - Code Style - - - UnnecessarySemicolon - Code Style - - - UnreachableCode - Code Style - - - UseConcatOnce - Code Style - - - UseDiamondOperator - Code Style - - - UseExplicitTypes - Code Style - - - UselessParentheses - Code Style - - - UselessQualifiedThis - Code Style - - - UseShortArrayInitializer - Code Style - - - UseUnderscoresInNumericLiterals - Code Style - - - WhileLoopsMustUseBraces - Code Style - - - AbstractClassWithoutAnyMethod - Design - - - AvoidCatchingGenericException - Design - - - AvoidDeeplyNestedIfStmts - Design - - - AvoidRethrowingException - Design - - - AvoidThrowingNewInstanceOfSameException - Design - - - AvoidThrowingNullPointerException - Design - - - AvoidThrowingRawExceptionTypes - Design - - - AvoidUncheckedExceptionsInSignatures - Design - - - ClassWithOnlyPrivateConstructorsShouldBeFinal - Design - - - CognitiveComplexity - Design - - - CollapsibleIfStatements - Design - - - CouplingBetweenObjects - Design - - - CyclomaticComplexity - Design - - - DataClass - Design - - - DoNotExtendJavaLangError - Design - - - ExceptionAsFlowControl - Design - - - ExcessiveClassLength - Design - - - ExcessiveImports - Design - - - ExcessiveMethodLength - Design - - - ExcessiveObjectLength - Design - - - ExcessivePackageBodyLength - Design - - - ExcessivePackageSpecificationLength - Design - - - ExcessiveParameterList - Design - - - ExcessivePublicCount - Design - - - ExcessiveTemplateLength - Design - - - ExcessiveTypeLength - Design - - - FinalFieldCouldBeStatic - Design - - - GodClass - Design - - - ImmutableField - Design - - - InvalidJavaBean - Design - - - LawOfDemeter - Design - - - LogicInversion - Design - - - LoosePackageCoupling - Design - - - MutableStaticState - Design - - - NcssConstructorCount - Design - - - NcssCount - Design - - - NcssMethodCount - Design - - - NcssObjectCount - Design - - - NcssTypeCount - Design - - - NoInlineJavaScript - Design - - - NoInlineScript - Design - - - NoInlineStyleInformation - Design - - - NoInlineStyles - Design - - - NoLongScripts - Design - - - NoScriptlets - Design - - - NPathComplexity - Design - - - SignatureDeclareThrowsException - Design - - - SimplifiedTernary - Design - - - SimplifyBooleanExpressions - Design - - - SimplifyBooleanReturns - Design - - - SimplifyConditional - Design - - - SingularField - Design - - - StdCyclomaticComplexity - Design - - - SwitchDensity - Design - - - TooManyFields - Design - - - TooManyMethods - Design - - - UnusedMethod - Design - - - UselessOverridingMethod - Design - - - UseObjectForClearerAPI - Design - - - UseUtilityClass - Design - - - ApexDoc - Documentation - - - CommentContent - Documentation - - - CommentRequired - Documentation - - - CommentSize - Documentation - - - UncommentedEmptyConstructor - Documentation - - - UncommentedEmptyMethodBody - Documentation - - - ApexCSRF - Error Prone - - - AssignmentToNonFinalStatic - Error Prone - - - AvoidAccessibilityAlteration - Error Prone - - - AvoidAssertAsIdentifier - Error Prone - - - AvoidBranchingStatementAsLastInLoop - Error Prone - - - AvoidCallingFinalize - Error Prone - - - AvoidCatchingNPE - Error Prone - - - AvoidCatchingThrowable - Error Prone - - - AvoidDecimalLiteralsInBigDecimalConstructor - Error Prone - - - AvoidDirectAccessTriggerMap - Error Prone - - - AvoidDuplicateLiterals - Error Prone - - - AvoidEnumAsIdentifier - Error Prone - - - AvoidFieldNameMatchingMethodName - Error Prone - - - AvoidFieldNameMatchingTypeName - Error Prone - - - AvoidHardcodingId - Error Prone - - - AvoidInstanceofChecksInCatchClause - Error Prone - - - AvoidLiteralsInIfCondition - Error Prone - - - AvoidLosingExceptionInformation - Error Prone - - - AvoidMultipleUnaryOperators - Error Prone - - - AvoidNonExistentAnnotations - Error Prone - - - AvoidStatefulDatabaseResult - Error Prone - - - AvoidTrailingComma - Error Prone - - - AvoidUsingOctalValues - Error Prone - - - BrokenNullCheck - Error Prone - - - CallSuperFirst - Error Prone - - - CallSuperLast - Error Prone - - - CheckSkipResult - Error Prone - - - ClassCastExceptionWithToArray - Error Prone - - - CloneMethodMustBePublic - Error Prone - - - CloneMethodMustImplementCloneable - Error Prone - - - CloneMethodReturnTypeMustMatchClassName - Error Prone - - - CloseResource - Error Prone - - - CompareObjectsWithEquals - Error Prone - - - ComparisonWithNaN - Error Prone - - - ConfusingArgumentToVarargsMethod - Error Prone - - - ConstructorCallsOverridableMethod - Error Prone - - - DetachedTestCase - Error Prone - - - DoNotCallGarbageCollectionExplicitly - Error Prone - - - DoNotExtendJavaLangThrowable - Error Prone - - - DoNotHardCodeSDCard - Error Prone - - - DoNotTerminateVM - Error Prone - - - DoNotThrowExceptionInFinally - Error Prone - - - DontImportSun - Error Prone - - - DontUseFloatTypeForLoopIndices - Error Prone - - - EmptyCatchBlock - Error Prone - - - EmptyFinalizer - Error Prone - - - EmptyForeachStmt - Error Prone - - - EmptyIfStmt - Error Prone - - - EmptyStatementBlock - Error Prone - - - EmptyTryOrFinallyBlock - Error Prone - - - EmptyWhileStmt - Error Prone - - - EqualComparison - Error Prone - - - EqualsNull - Error Prone - - - FinalizeDoesNotCallSuperFinalize - Error Prone - - - FinalizeOnlyCallsSuperFinalize - Error Prone - - - FinalizeOverloaded - Error Prone - - - FinalizeShouldBeProtected - Error Prone - - - ForceCast - Error Prone - - - ForceTry - Error Prone - - - IdempotentOperations - Error Prone - - - ImplicitSwitchFallThrough - Error Prone - - - InaccessibleAuraEnabledGetter - Error Prone - - - InaccurateNumericLiteral - Error Prone - - - InstantiationToGetClass - Error Prone - - - InvalidDependencyTypes - Error Prone - - - InvalidLogMessageFormat - Error Prone - - - JspEncoding - Error Prone - - - JumbledIncrementer - Error Prone - - - JUnitSpelling - Error Prone - - - JUnitStaticSuite - Error Prone - - - MethodWithSameNameAsEnclosingClass - Error Prone - - - MisplacedNullCheck - Error Prone - - - MissingSerialVersionUID - Error Prone - - - MissingStaticMethodInNonInstantiatableClass - Error Prone - - - MistypedCDATASection - Error Prone - - - MoreThanOneLogger - Error Prone - - - NonCaseLabelInSwitch - Error Prone - - - NonSerializableClass - Error Prone - - - NonStaticInitializer - Error Prone - - - NullAssignment - Error Prone - - - OverrideBothEqualsAndHashcode - Error Prone - - - ProjectVersionAsDependencyVersion - Error Prone - - - ProperCloneImplementation - Error Prone - - - ProperLogger - Error Prone - - - ReturnEmptyCollectionRatherThanNull - Error Prone - - - ReturnFromFinallyBlock - Error Prone - - - SimpleDateFormatNeedsLocale - Error Prone - - - SingleMethodSingleton - Error Prone - - - SingletonClassReturningNewInstance - Error Prone - - - StaticEJBFieldShouldBeFinal - Error Prone - - - StringBufferInstantiationWithChar - Error Prone - - - SuspiciousEqualsMethodName - Error Prone - - - SuspiciousHashcodeMethodName - Error Prone - - - SuspiciousOctalEscape - Error Prone - - - TestClassWithoutTestCases - Error Prone - - - TestMethodsMustBeInTestClasses - Error Prone - - - TO_DATEWithoutDateFormat - Error Prone - - - TO_DATE_TO_CHAR - Error Prone - - - TO_TIMESTAMPWithoutDateFormat - Error Prone - - - TypeShadowsBuiltInNamespace - Error Prone - - - UnconditionalIfStatement - Error Prone - - - UnnecessaryBooleanAssertion - Error Prone - - - UnnecessaryCaseChange - Error Prone - - - UnnecessaryConversionTemporary - Error Prone - - - UnusedNullCheckInEquals - Error Prone - - - UseCorrectExceptionLogging - Error Prone - - - UseEqualsToCompareStrings - Error Prone - - - UselessOperationOnImmutable - Error Prone - - - UseLocaleWithCaseConversions - Error Prone - - - UseProperClassLoader - Error Prone - - - AvoidSynchronizedAtMethodLevel - Multithreading - - - AvoidSynchronizedStatement - Multithreading - - - AvoidThreadGroup - Multithreading - - - AvoidUsingVolatile - Multithreading - - - DoNotUseThreads - Multithreading - - - DontCallThreadRun - Multithreading - - - DoubleCheckedLocking - Multithreading - - - NonThreadSafeSingleton - Multithreading - - - UnsynchronizedStaticFormatter - Multithreading - - - UseConcurrentHashMap - Multithreading - - - UseNotifyAllInsteadOfNotify - Multithreading - - - AddEmptyString - Performance - - - AppendCharacterWithChar - Performance - - - AvoidArrayLoops - Performance - - - AvoidAxisNavigation - Performance - - - AvoidCalendarDateCreation - Performance - - - AvoidConsoleStatements - Performance - - - AvoidDebugStatements - Performance - - - AvoidFileStream - Performance - - - AvoidInstantiatingObjectsInLoops - Performance - - - AvoidNonRestrictiveQueries - Performance - - - BigIntegerInstantiation - Performance - - - ConsecutiveAppendsShouldReuse - Performance - - - ConsecutiveLiteralAppends - Performance - - - EagerlyLoadedDescribeSObjectResult - Performance - - - InefficientEmptyStringCheck - Performance - - - InefficientStringBuffering - Performance - - - InsufficientStringBufferDeclaration - Performance - - - OperationWithHighCostInLoop - Performance - - - OperationWithLimitsInLoop - Performance - - - OptimizableToArrayCall - Performance - - - RedundantFieldInitializer - Performance - - - StringInstantiation - Performance - - - StringToString - Performance - - - TooFewBranchesForSwitch - Performance - - - UseArrayListInsteadOfVector - Performance - - - UseArraysAsList - Performance - - - UseIndexOfChar - Performance - - - UseIOStreamsWithApacheCommonsFileItem - Performance - - - UselessStringValueOf - Performance - - - UseStringBufferForStringAppends - Performance - - - UseStringBufferLength - Performance - - - ApexBadCrypto - Security - - - ApexCRUDViolation - Security - - - ApexDangerousMethods - Security - - - ApexInsecureEndpoint - Security - - - ApexOpenRedirect - Security - - - ApexSharingViolations - Security - - - ApexSOQLInjection - Security - - - ApexSuggestUsingNamedCred - Security - - - ApexXSSFromEscapeFalse - Security - - - ApexXSSFromURLParam - Security - - - HardCodedCryptoKey - Security - - - IframeMissingSrcAttribute - Security - - - InsecureCryptoIv - Security - - - NoUnsanitizedJSPExpression - Security - - - VfCsrf - Security - - - VfHtmlStyleTagXss - Security - - - VfUnescapeEl - Security - - + true + .ruleset false true true diff --git a/.ruleset b/.ruleset new file mode 100644 index 0000000..fa12e58 --- /dev/null +++ b/.ruleset @@ -0,0 +1,298 @@ + + + Egothor preferences rule set + .* + .*\.java + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle index 79993f9..c93c2f8 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'java-library' id 'maven-publish' id 'com.palantir.git-version' version '4.0.0' + id 'pmd' } group 'org.egothor' @@ -20,6 +21,13 @@ dependencies { testRuntimeOnly("org.junit.platform:junit-platform-launcher") } +pmd { + consoleOutput = true + toolVersion = '7.16.0' + sourceSets = [sourceSets.main] + ruleSetFiles = files(rootProject.file(".ruleset")) +} + // Apply a specific Java toolchain to ease working on different environments. java { toolchain { diff --git a/src/main/java/conflux/CtxInstance.java b/src/main/java/conflux/CtxInstance.java index 8e1f355..250e928 100644 --- a/src/main/java/conflux/CtxInstance.java +++ b/src/main/java/conflux/CtxInstance.java @@ -108,10 +108,10 @@ public final class CtxInstance implements CtxInterface { } // notify listeners - var list = listeners.get(key); + List>> list = listeners.get(key); if (list != null) { - for (var ref : list) { - var listener = ref.get(); + for (WeakReference> ref : list) { + Listener listener = ref.get(); if (listener != null) { @SuppressWarnings("unchecked") Listener typedListener = (Listener) listener; @@ -156,7 +156,7 @@ public final class CtxInstance implements CtxInterface { @Override public Object remove(Key key) { keyTypes.remove(key.name()); - var removed = values.remove(key); + Object removed = values.remove(key); listeners.remove(key); return removed; } @@ -193,10 +193,10 @@ public final class CtxInstance implements CtxInterface { */ @Override public void removeListener(Key key, Listener listener) { - var list = listeners.get(key); + List>> list = listeners.get(key); if (list != null) { list.removeIf(ref -> { - var l = ref.get(); + Listener l = ref.get(); return l == null || l.equals(listener); }); if (list.isEmpty()) { diff --git a/src/main/java/conflux/Key.java b/src/main/java/conflux/Key.java index 8170383..53f928d 100644 --- a/src/main/java/conflux/Key.java +++ b/src/main/java/conflux/Key.java @@ -42,19 +42,19 @@ package conflux; * @author Leo Galambos */ public final class Key { // NOPMD by Leo Galambos on 7/3/25, 10:29 PM - private final String name; - private final Class type; + private final String nameField; + private final Class typeField; private Key(String name, Class type) { - this.name = name; - this.type = type; + this.nameField = name; + this.typeField = type; } /** * Creates a new typed key. * - * @param name a unique key name - * @param type the class of the key's value type + * @param name a unique key nameField + * @param type the class of the key's value typeField * @param the type * @return a new {@code Key} */ @@ -68,7 +68,7 @@ public final class Key { // NOPMD by Leo Galambos on 7/3/25, 10:29 PM * @return the name */ public String name() { - return name; + return nameField; } /** @@ -77,21 +77,21 @@ public final class Key { // NOPMD by Leo Galambos on 7/3/25, 10:29 PM * @return the type */ public Class type() { - return type; + return typeField; } @Override public int hashCode() { - return name.hashCode(); + return nameField.hashCode(); } @Override public boolean equals(Object obj) { - return obj instanceof Key other && name.equals(other.name); + return obj instanceof Key other && nameField.equals(other.nameField); } @Override public String toString() { - return "Key[" + name + ", " + type.getSimpleName() + "]"; + return "Key[" + nameField + ", " + typeField.getSimpleName() + "]"; } } \ No newline at end of file