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

[PR] Fix NullPointerException in SIngleTargetMapping when source or suffix… [maven-shared-io]

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

   … is null (#94)
   
   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
   - [ ] Your pull request should address just one issue, without pulling in other changes.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Each commit in the pull request should have a meaningful subject line and body.
     Note that commits might be squashed by a maintainer on merge.
   - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
     This may not always be possible but is a best-practice.
   - [ ] Run `mvn verify` to make sure basic checks pass.
     A more thorough check will be performed on your pull request automatically.
   - [ ] You have run the integration tests successfully (`mvn -Prun-its verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [ ] 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)
   - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
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] Fix NullPointerException in SingleTargetMapping when source or suffix… [maven-shared-io]

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


##########
src/test/java/org/apache/maven/shared/io/scan/mapping/SingleTargetMappingTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.io.scan.mapping;
+
+import java.io.File;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SingleTargetMappingTest {
+
+    @Test
+    void testGetTargetFilesShouldReturnEmptySetWhenSuffixDoesNotMatch() throws Exception {
+        SingleTargetMapping mapping = new SingleTargetMapping(".cs", "/foo");
+        File basedir = new File("target/");
+
+        Set<File> results = mapping.getTargetFiles(basedir, "path/to/file.apt");
+
+        assertTrue(results.isEmpty());
+    }
+
+    @Test
+    void testGetTargetFilesShouldReturnCorrectFileWhenSuffixMatches() throws Exception {
+        SingleTargetMapping mapping = new SingleTargetMapping(".cs", "/foo");
+        File basedir = new File("target/");
+
+        Set<File> results = mapping.getTargetFiles(basedir, "path/to/file.cs");
+
+        assertEquals(1, results.size());
+        assertEquals(new File(basedir, "/foo"), results.iterator().next());
+    }

Review Comment:
   The tests use an absolute outputFile ("/foo"), which causes `new File(basedir, "/foo")` to ignore `basedir` and makes the test not actually verify how `targetDir` is applied. Using a relative output file (e.g. "foo") keeps the assertion platform-neutral and validates the intended `new File(targetDir, outputFile)` behavior.
   
   This issue also appears on line 54 of the same file.



-- 
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] Fix NullPointerException in SingleTargetMapping when source or suffix… [maven-shared-io]

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


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