Skip to content

NPE reporting fix#580

Merged
nickl- merged 1 commit into
beanshell:masterfrom
christiancairney:BSH_BSF_NPEReporting
Dec 27, 2022
Merged

NPE reporting fix#580
nickl- merged 1 commit into
beanshell:masterfrom
christiancairney:BSH_BSF_NPEReporting

Conversation

@christiancairney

@christiancairney christiancairney commented Jan 9, 2020

Copy link
Copy Markdown

Beanshell emitting NPE's via the BSF integeration just throws an error reporting a "NullPointerException" in line 0.

This fix adds meta data to the NPE giving the line number and the offending line.

Fixes #572

@codecov

codecov Bot commented Jan 9, 2020

Copy link
Copy Markdown

Codecov Report

Merging #580 into master will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #580      +/-   ##
============================================
+ Coverage     70.35%   70.43%   +0.07%     
- Complexity     2692     2695       +3     
============================================
  Files           106      106              
  Lines          8945     8945              
  Branches       1765     1765              
============================================
+ Hits           6293     6300       +7     
+ Misses         2219     2215       -4     
+ Partials        433      430       -3
Impacted Files Coverage Δ Complexity Δ
src/main/java/bsh/commands/dir.java 60.37% <0%> (+1.88%) 4% <0%> (ø) ⬇️
src/main/java/bsh/classpath/ClassManagerImpl.java 64.67% <0%> (+3.59%) 39% <0%> (+3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53be487...580c801. Read the comment docs.

@nickl- nickl- left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with the changes made to errorMessage but please remove the iniCause redundancies as the Throwable is already passed in the constructor.

} catch ( EvalError e ) {
throw new BSFException(BSFException.REASON_OTHER_ERROR, "bsh internal error: "+e, e);
BSFException bsf = new BSFException(BSFException.REASON_OTHER_ERROR, "bsh internal error: "+e, e);
bsf.initCause(e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is redundant as we are already passing e to the constructor.

@christiancairney christiancairney Jan 19, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Happy to make this change, although the reason why this was done is to ensure the BSFException supported Exception chaining.

AFAIK The BSFException class does not populate the cause of the exception use the constructor (Most up to date one I found was at: https://github.com/apache/commons-bsf/blob/master/src/main/java/org/apache/bsf/BSFException.java) :

public BSFException (int reason, String msg, Throwable t) {
    this (reason, msg);
    targetThrowable = t;
  }

It tracks the throwable via a class variable "targetThrowable" which is exposed using the getTargetException() method. The getTargetException() method was superseded by getCause() for general purpose exception chaining.

Initialising the cause ensures they getCause() returns the expected, removing the initCause() stopped exception chaining working for me.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@nickl- I'll hold off making the change until you've commented on the exception chaining issue and if the desire is to keep exception chaining disabled. BR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see well spotted!! initCause will be the desired route then.

@nickl- nickl- merged commit 60c74f1 into beanshell:master Dec 27, 2022
pgiffuni pushed a commit to pgiffuni/beanshell that referenced this pull request Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Beanshell via BSF unhelpful Null Pointer Exception in line 0 issue

3 participants