Skip to content

Fix NPEs in SuffixMapping, SingleTargetMapping, and URLLocation - #119

Open
itsmehotpants wants to merge 1 commit into
apache:masterfrom
itsmehotpants:fix/npe-null-checks
Open

Fix NPEs in SuffixMapping, SingleTargetMapping, and URLLocation#119
itsmehotpants wants to merge 1 commit into
apache:masterfrom
itsmehotpants:fix/npe-null-checks

Conversation

@itsmehotpants

Copy link
Copy Markdown

What

Fixes three related NullPointerException bugs:

  • SuffixMapping#getTargetFiles threw NPE from source.endsWith(sourceSuffix) when either argument was null.
  • SingleTargetMapping#getTargetFiles had the same endsWith(null) NPE pattern.
  • URLLocation#initFile threw NPE from Files.createTempFile(tempFilePrefix, tempFileSuffix) when the prefix/suffix constructor args were null (allowed by the public constructor).

Fix

  • SuffixMapping / SingleTargetMapping: guard with a null check before calling endsWith, returning an empty result set (no match) instead of throwing.
  • URLLocation: fall back to default values ("url" / ".tmp") when the prefix/suffix are null, consistent with how the constructor already allows them to be null.

Testing

Added regression tests for each case following the existing test style in SuffixMappingTest and URLLocationTest.

Fixes #93
Fixes #94
Fixes #95

- SuffixMapping#getTargetFiles: guard against null source/sourceSuffix
  before calling String#endsWith, returning an empty result set instead
  of throwing NullPointerException.
- SingleTargetMapping#getTargetFiles: same guard for the same
  endsWith(null) NPE pattern.
- URLLocation#initFile: fall back to default temp-file prefix/suffix
  ("url" / ".tmp") when the caller passes null, instead of letting
  Files.createTempFile(null, null) throw NullPointerException.

Adds regression tests for each case, matching the existing test style.

Fixes apache#93, Fixes apache#94, Fixes apache#95

@elharo elharo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three issues should be three PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants