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

   `SuffixMapping.getTargetFiles()` calls `source.endsWith(sourceSuffix)` 
unconditionally. Both `source` and `sourceSuffix` can be null through the 
public constructor (`SuffixMapping(String sourceSuffix, String targetSuffix)` 
takes no null checks), and either one being null throws an NPE:
   
   ```
   java.lang.NullPointerException: Cannot invoke "String.endsWith(String)" 
because "source" is null
        at 
org.apache.maven.shared.io.scan.mapping.SuffixMapping.getTargetFiles(SuffixMapping.java:59)
   
   java.lang.NullPointerException: Cannot invoke "String.length()" because 
"suffix" is null
        at java.base/java.lang.String.endsWith(String.java:2331)
        at 
org.apache.maven.shared.io.scan.mapping.SuffixMapping.getTargetFiles(SuffixMapping.java:59)
   ```
   
   Fixes #93
   
   ### Changes
   
   - Guard the `endsWith` call so a null `source` or `sourceSuffix` is treated 
as a non-match (returns an empty target set), matching the existing behavior 
for a suffix mismatch.
   - Added two tests (`shouldReturnNoTargetFilesWhenSourceSuffixIsNull`, 
`shouldReturnNoTargetFilesWhenSourceIsNull`) that reproduce the NPE before the 
fix and pass after it.
   
   `mvn test -Dtest=SuffixMappingTest` and `mvn verify` pass locally.
   
   - [x] I hereby declare this contribution to be licenced under the [Apache 
License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)


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