elharo opened a new issue, #204:
URL: https://github.com/apache/maven-script-interpreter/issues/204

   **Describe the bug**
   
   `FileLogger(File outputFile, FileLoggerMirrorHandler)` throws a 
`NullPointerException` when the output file has no parent directory. The 
constructor calls `Files.createDirectories(outputPath.getParent())` 
unconditionally for a non-null file (FileLogger.java:68); for a bare filename 
such as `new File("build.log")`, `getParent()` is `null` and 
`Files.createDirectories(null)` fails with an NPE.
   
   **To Reproduce**
   
   ```java
   try (FileLogger logger = new FileLogger(new File("build.log"))) {
       logger.consumeLine("test");
   }
   ```
   
   **Expected behavior**
   
   The log file is created in the current working directory.
   
   **Actual behavior**
   
   `java.lang.NullPointerException` thrown from the constructor because 
`outputPath.getParent()` is `null`.
   
   **Suggested fix**
   
   Guard the parent lookup, e.g.:
   
   ```java
   if (outputFile != null) {
       Path outputPath = outputFile.toPath();
       Path parent = outputPath.getParent();
       if (parent != null) {
           Files.createDirectories(parent);
       }
       outputStream = createOutputStream(outputPath);
   }
   ```
   
   **Environment**
   
   maven-script-interpreter 1.9-SNAPSHOT, all JDK versions.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to