GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] HardCodedCryptoKey: NPE when constants from parent class are used by zbynek · Pull Request #6191 · pmd/pmd

Conversation

@zbynek

@zbynek zbynek commented Oct 30, 2025 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

Rule: HardCodedCryptoKey

Adds a null check in case the accessed field is not defined in the current class. When the null check fails, check if the field is a compile time constant.

The changed code is shared with InsecureCryptoIv, the fix applies to both rules.

For reference, the fixed NPE stacktrace
[WARNING] Exception applying rule HardCodedCryptoKey on file /home/mag/project/civitas-ng/civitas.externalcrypto/src/test/java/civitas/crypto/CryptoBaseTest.java, continuing with next rule
org.apache.commons.lang3.exception.ContextedRuntimeException: java.lang.NullPointerException: Cannot invoke "net.sourceforge.pmd.lang.java.ast.ASTVariableId.getInitializer()" because "varDecl" is null
Exception Context:
        [1:Rule applied on node=!debug only! [ConstructorCall:82:28]new SecretKeySpec(SOMESTRING.getBytes(), SHARED_KEY_ALG)]
---------------------------------
    at net.sourceforge.pmd.util.AssertionUtil.contexted (AssertionUtil.java:257)
    at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex (RuleApplicator.java:79)
    at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply (RuleApplicator.java:57)
    at net.sourceforge.pmd.lang.rule.internal.RuleSets.apply (RuleSets.java:183)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource (PmdRunnable.java:140)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.run (PmdRunnable.java:80)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
    at java.util.concurrent.FutureTask.run (FutureTask.java:317)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    at java.lang.Thread.run (Thread.java:1583)
Caused by: java.lang.NullPointerException: Cannot invoke "net.sourceforge.pmd.lang.java.ast.ASTVariableId.getInitializer()" because "varDecl" is null
    at net.sourceforge.pmd.lang.java.rule.security.AbstractHardCodedConstructorArgsVisitor.validateProperKeyArgument (AbstractHardCodedConstructorArgsVisitor.java:68)
    at net.sourceforge.pmd.lang.java.rule.security.AbstractHardCodedConstructorArgsVisitor.visit (AbstractHardCodedConstructorArgsVisitor.java:35)
    at net.sourceforge.pmd.lang.java.rule.security.HardCodedCryptoKeyRule.visit (HardCodedCryptoKeyRule.java:14)
    at net.sourceforge.pmd.lang.java.ast.ASTConstructorCall.acceptVisitor (ASTConstructorCall.java:34)
    at net.sourceforge.pmd.lang.java.ast.AbstractJavaNode.acceptVisitor (AbstractJavaNode.java:38)
    at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply (AbstractJavaRule.java:30)
    at net.sourceforge.pmd.lang.rule.RuleReference.apply (RuleReference.java:413)
    at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.applyOnIndex (RuleApplicator.java:77)
    at net.sourceforge.pmd.lang.rule.internal.RuleApplicator.apply (RuleApplicator.java:57)
    at net.sourceforge.pmd.lang.rule.internal.RuleSets.apply (RuleSets.java:183)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource (PmdRunnable.java:140)
    at net.sourceforge.pmd.lang.impl.PmdRunnable.run (PmdRunnable.java:80)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:572)
    at java.util.concurrent.FutureTask.run (FutureTask.java:317)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    at java.lang.Thread.run (Thread.java:1583)

Related issues

reported in discussion #6186

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zbynek
zbynek force-pushed the crypto branch from d1ac82f to dc285be Compare October 30, 2025 00:32
@pmd-actions-helper

pmd-actions-helper Bot commented Oct 30, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

No regression tested rules have been changed.

(comment created at 2025-10-30 12:10:05+00:00 for f412ba4)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 7.18.0 milestone Oct 30, 2025
adangel
adangel approved these changes Oct 30, 2025
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel adangel added the a:bug PMD crashes or fails to analyse a file. label Oct 30, 2025
@adangel adangel changed the title [java] HardCodedCryptoKey: report constants from parent class [java] HardCodedCryptoKey: NPE when constants from parent class are used Oct 30, 2025
zbynek and others added 2 commits October 30, 2025 12:49
@zbynek @adangel
[java] HardCodedCryptoKey: report constants from parent class
4d7cc32
@adangel
[doc] Update release notes (pmd#6191)
f412ba4
@adangel
adangel force-pushed the crypto branch from dc285be to f412ba4 Compare October 30, 2025 11:51
@adangel
adangel merged commit 39be706 into pmd:main Oct 30, 2025
magwas pushed a commit to magwas/pmd that referenced this pull request Nov 1, 2025
@adangel @magwas
[doc] Update release notes (pmd#6191)
fd35917
@magwas magwas mentioned this pull request Nov 1, 2025
pmd non-fatal errors edemo/civitas-ng#33
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

a:bug PMD crashes or fails to analyse a file.

Projects

None yet

Milestone

7.18.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@zbynek @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.