Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. - #118
Conversation
| protected void initFile() throws IOException { | ||
| if (unsafeGetFile() == null) { | ||
| File tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix).toFile(); | ||
| String prefix = tempFilePrefix != null ? tempFilePrefix : DEFAULT_TEMP_FILE_PREFIX; |
There was a problem hiding this comment.
cleaner to do this in the constructor
There was a problem hiding this comment.
Thanks for the review! Agreed on both points — I'll move the null defaulting into the constructor so tempFilePrefix/tempFileSuffix are guaranteed non-null by the time initFile() runs, and inline the "url"/".tmp" literals directly instead of the named constants. Will push an update shortly.
| */ | ||
| public class URLLocation extends FileLocation { | ||
|
|
||
| private static final String DEFAULT_TEMP_FILE_PREFIX = "url"; |
There was a problem hiding this comment.
I'm tempted to just inline these
There was a problem hiding this comment.
Thanks for the review, @elharo — both points are addressed now.
Changes to URLLocation.java:
- Removed the two
static finalconstants - Constructor now applies null-safe defaults inline:
this.tempFilePrefix = (tempFilePrefix != null) ? tempFilePrefix : "url";
this.tempFileSuffix = (tempFileSuffix != null) ? tempFileSuffix : ".tmp";initFile()reverted to the original one-liner (fields are now guaranteed non-null)- Existing regression test left unchanged — still passes
mvn -q test passed. Commit amended and force-pushed to fix-95-urllocation-tempfile-defaults.
Provide safe defaults for temp file prefix/suffix when null and add regression test for issue apache#95. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ae904bb to
97a000e
Compare
|
@elharo Please assign appropriate label to PR according to the type of change. |
Summary
This pull request fixes issue #95 by providing safe default values when
URLLocationcreates a temporary file usingFiles.createTempFile(...).Previously, passing
nullas the prefix or suffix resulted in aNullPointerException.Changes
"url"as the default prefix when the provided prefix isnull".tmp"as the default suffix when the provided suffix isnullFixes #95