From 768099b1f9718930b516837a72b59084448b0620 Mon Sep 17 00:00:00 2001 From: Judit Knoll Date: Fri, 13 Oct 2023 15:38:14 +0200 Subject: [PATCH] Fix missing null checks --- .../cs/findbugs/detect/FindArgumentAssertions.java | 14 ++++++++------ .../detect/FindAssertionsWithSideEffects.java | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java index 1ac3cdaaf0c..cd8db31acd5 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindArgumentAssertions.java @@ -56,12 +56,14 @@ public void visitClassContext(ClassContext classContext) { */ private boolean isInitialArg() { XMethod m = getXMethodOperand(); - int numPar = m.getNumParams(); - // Get values from the stack - for (int i = 0; i < numPar; i++) { - Item item = stack.getStackItem(i); - if (item.isInitialParameter()) - return true; + if (m != null) { + int numPar = m.getNumParams(); + // Get values from the stack + for (int i = 0; i < numPar; i++) { + Item item = stack.getStackItem(i); + if (item.isInitialParameter()) + return true; + } } return false; } diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java index 431baa46572..bf9ff39c295 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindAssertionsWithSideEffects.java @@ -61,7 +61,7 @@ private boolean checkSeen(int seen) { */ @Override protected void detect(int seen) { - if (isMethodCall(seen)) { + if (isMethodCall(seen) && getXClassOperand() != null && getXMethodOperand() != null) { String retSig = new SignatureParser(getXMethodOperand().getSignature()).getReturnTypeSignature(); String classSig = getXClassOperand().getSourceSignature(); if (MutableClasses.mutableSignature("L" + getClassConstantOperand() + ";") &&