You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "LuckysHorizon (via GitHub)" <gi...@apache.org> on 2026/07/19 13:42:33 UTC

[PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

LuckysHorizon opened a new pull request, #118:
URL: https://github.com/apache/maven-shared-io/pull/118

   ## Summary
   
   This pull request fixes issue #95 by providing safe default values when
   `URLLocation` creates a temporary file using `Files.createTempFile(...)`.
   
   Previously, passing `null` as the prefix or suffix resulted in a
   `NullPointerException`.
   
   ### Changes
   
   - Use `"url"` as the default prefix when the provided prefix is `null`
   - Use `".tmp"` as the default suffix when the provided suffix is `null`
   - Add a regression test covering this behavior
   
   Fixes #95


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #118:
URL: https://github.com/apache/maven-shared-io/pull/118#issuecomment-5147786676

   @elharo Please assign appropriate label to PR according to the type of change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #118:
URL: https://github.com/apache/maven-shared-io/pull/118#discussion_r3691245035


##########
src/main/java/org/apache/maven/shared/io/location/URLLocation.java:
##########
@@ -30,6 +30,10 @@
  */
 public class URLLocation extends FileLocation {
 
+    private static final String DEFAULT_TEMP_FILE_PREFIX = "url";

Review Comment:
   I'm tempted to just inline these



##########
src/main/java/org/apache/maven/shared/io/location/URLLocation.java:
##########
@@ -58,7 +62,10 @@ public URLLocation(
     /** {@inheritDoc} */
     protected void initFile() throws IOException {
         if (unsafeGetFile() == null) {
-            File tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix).toFile();
+            String prefix = tempFilePrefix != null ? tempFilePrefix : DEFAULT_TEMP_FILE_PREFIX;

Review Comment:
   cleaner to do this in the constructor



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

Posted by "LuckysHorizon (via GitHub)" <gi...@apache.org>.
LuckysHorizon commented on code in PR #118:
URL: https://github.com/apache/maven-shared-io/pull/118#discussion_r3692235163


##########
src/main/java/org/apache/maven/shared/io/location/URLLocation.java:
##########
@@ -30,6 +30,10 @@
  */
 public class URLLocation extends FileLocation {
 
+    private static final String DEFAULT_TEMP_FILE_PREFIX = "url";

Review Comment:
   Thanks for the review, @elharo — both points are addressed now.
   
   **Changes to `URLLocation.java`:**
   - Removed the two `static final` constants
   - Constructor now applies null-safe defaults inline:
   ```java
     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`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

Posted by "LuckysHorizon (via GitHub)" <gi...@apache.org>.
LuckysHorizon commented on code in PR #118:
URL: https://github.com/apache/maven-shared-io/pull/118#discussion_r3692183474


##########
src/main/java/org/apache/maven/shared/io/location/URLLocation.java:
##########
@@ -58,7 +62,10 @@ public URLLocation(
     /** {@inheritDoc} */
     protected void initFile() throws IOException {
         if (unsafeGetFile() == null) {
-            File tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix).toFile();
+            String prefix = tempFilePrefix != null ? tempFilePrefix : DEFAULT_TEMP_FILE_PREFIX;

Review 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Provide safe defaults for temp file prefix/suffix when null and add regression test for issue #95. [maven-shared-io]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo merged PR #118:
URL: https://github.com/apache/maven-shared-io/pull/118


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org