Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential NPE in Spring module when handling exceptions #93

Open
altifuse opened this issue Aug 20, 2019 · 4 comments
Open

Potential NPE in Spring module when handling exceptions #93

altifuse opened this issue Aug 20, 2019 · 4 comments
Assignees
Labels

Comments

@altifuse
Copy link

When intercepted code throws exceptions, these are added to the current segment:

} catch (Exception e) {
AWSXRay.getCurrentSegment().addException(e);

However, when the segment does not exist, I'm experiencing NPEs (using v2.2.1). This seems similar to #41, which referenced the same method, but this is a different case.

@chanchiem
Copy link
Contributor

Hey,

Thanks for reporting the issue you are having. The expected behavior for this would be that the call to AWSXRay.getCurrentSegment() would throw a SegmentNotFoundException in the call to getCurrentSegment() if the context missing strategy was to throw runtime exceptions.

It looks like you've identified an edge case where if for some reason, the code path for getCurrentSegment() is allowed to continue executing (and thereby return a null object), then the call to addException() would still occur for a null object, thus throwing a NPE.

I think a fix would be to have an explicit check for this case to ensure that the object returned isn't null in case if the customer has a configuration to not throw exceptions (such as LogErrorContextMissingStrategy).

So instead of

} catch (Exception e) {
AWSXRay.getCurrentSegment().addException(e);
throw e;
} finally {

It should be

        } catch (Exception e) {
            Segment currentSegment = AWSXRay.getCurrentSegment();
            if (currentSegment != null) {
                currentSegment.addException(e);
            }
            throw e;
        } finally {

Some things I wanted to ask to verify some of the assumptions above:

  • Are you experiencing any other exceptions like the ContextMissingException?
  • What context missing strategy are you using? LogErrorContextMissingStrategy?

Thanks!

@altifuse
Copy link
Author

Thanks for the response, @chanchiem.

I agree with your proposed fix. From what I've gathered that would be enough.

Regarding your questions:

Are you experiencing any other exceptions like the ContextMissingException?
What context missing strategy are you using? LogErrorContextMissingStrategy?

Yes, that's the strategy we are using. There are logs mentioning the suppression of SubsegmentNotFoundException and SegmentNotFoundException.

@awssandra awssandra added the bug label Jan 10, 2020
@altifuse
Copy link
Author

Are there any updates on this?

@chanchiem
Copy link
Contributor

Hey, we have this in our priority and will come out with a PR. Please stay tuned.

chanchiem added a commit to chanchiem/aws-xray-sdk-java that referenced this issue Jan 23, 2020
…ws#93)

Adds a null check prior to adding the exception to the segment.
shengxil pushed a commit that referenced this issue Jan 29, 2020
…93)

Adds a null check prior to adding the exception to the segment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants