Skip to content

Fix: Add null check for context parameter in XenditException constructor#136

Open
prjanitor wants to merge 1 commit intoxendit:masterfrom
prjanitor:prjanitor/a06f1bb83a08422b2aebc82f562ae80aeb5683b0
Open

Fix: Add null check for context parameter in XenditException constructor#136
prjanitor wants to merge 1 commit intoxendit:masterfrom
prjanitor:prjanitor/a06f1bb83a08422b2aebc82f562ae80aeb5683b0

Conversation

@prjanitor
Copy link
Copy Markdown

Summary

This PR fixes a null pointer vulnerability in the XenditException class where the context parameter could be null, causing NullPointerException when client code attempts to iterate or access the context map.

Changes

  1. Added import for java.util.Collections
  2. Modified the two-argument constructor to check if context is null and initialize it to Collections.emptyMap() if so

Before

public XenditException(String message, String code, Map<String, Object> context) {
    super(message);
    this.code = code;
    this.context = context;  // Could be null!
}

After

public XenditException(String message, String code, Map<String, Object> context) {
    super(message);
    this.code = code;
    this.context = context != null ? context : Collections.emptyMap();
}

Benefits

  • getContext() will never return null
  • Client code can safely iterate over the context without null checks
  • Follows Java best practices using Collections.emptyMap() for immutable empty collections

This PR was generated by PRJanitor — an automated tool that finds and fixes small bugs in open-source projects.

We respect your contribution guidelines — if your project doesn't accept bot PRs, we won't send more. You can also add a .github/prjanitor.yml file with enabled: false to opt out explicitly.

The XenditException constructor now validates the context parameter and initializes it to an empty map if null is passed. This prevents NullPointerException when client code attempts to iterate or access the context map without null checking.
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.

1 participant