Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public URLLocation(
/** {@inheritDoc} */
protected void initFile() throws IOException {
if (unsafeGetFile() == null) {
File tempFile = Files.createTempFile(tempFilePrefix, tempFileSuffix).toFile();
String prefix = tempFilePrefix == null ? "url" : tempFilePrefix;
String suffix = tempFileSuffix == null ? ".tmp" : tempFileSuffix;

File tempFile = Files.createTempFile(prefix, suffix).toFile();

if (tempFileDeleteOnExit) {
tempFile.deleteOnExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SingleTargetMapping(String sourceSuffix, String outputFile) {

/** {@inheritDoc} */
public Set<File> getTargetFiles(File targetDir, String source) throws InclusionScanException {
if (!source.endsWith(sourceSuffix)) {
if (source == null || sourceSuffix == null || !source.endsWith(sourceSuffix)) {
return Collections.<File>emptySet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public SuffixMapping(String sourceSuffix, Set<String> targetSuffixes) {
public Set<File> getTargetFiles(File targetDir, String source) {
Set<File> targetFiles = new HashSet<>();

if (source == null || sourceSuffix == null) {
return targetFiles;
}

if (source.endsWith(sourceSuffix)) {
String base = source.substring(0, source.length() - sourceSuffix.length());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ void shouldTransferFromTempFileThenRead() throws Exception {

assertEquals(testStr, new String(buffer, "US-ASCII"));
}

@Test
void shouldNotThrowNpeWhenTempFilePrefixAndSuffixAreNull() throws Exception {
File f = Files.createTempFile("url-location.", ".test").toFile();
f.deleteOnExit();

URL url = f.toURL();

URLLocation location = new URLLocation(url, f.getAbsolutePath(), null, null, true);

assertNotNull(location.getFile());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ void shouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() throws Exception {
assertTrue(results.isEmpty(), "Returned wrong number of target files.");
}

@Test
void shouldReturnNoTargetFilesWhenSourceIsNull() throws Exception {
File basedir = new File(".");

SuffixMapping mapping = new SuffixMapping(".java", ".class");

Set<File> results = mapping.getTargetFiles(basedir, null);

assertTrue(results.isEmpty(), "Returned wrong number of target files.");
}

@Test
void shouldReturnNoTargetFilesWhenSourceSuffixIsNull() throws Exception {
String base = "path/to/file";

File basedir = new File(".");

SuffixMapping mapping = new SuffixMapping(null, ".class");

Set<File> results = mapping.getTargetFiles(basedir, base + ".java");

assertTrue(results.isEmpty(), "Returned wrong number of target files.");
}

@Test
void singleTargetMapper() throws Exception {
String base = "path/to/file";
Expand All @@ -113,4 +137,28 @@ void singleTargetMapper() throws Exception {

assertEquals(1, results.size());
}

@Test
void singleTargetMapperShouldReturnNoTargetFilesWhenSourceIsNull() throws Exception {
File basedir = new File("target/");

SingleTargetMapping mapping = new SingleTargetMapping(".cs", "/foo");

Set<File> results = mapping.getTargetFiles(basedir, null);

assertTrue(results.isEmpty());
}

@Test
void singleTargetMapperShouldReturnNoTargetFilesWhenSourceSuffixIsNull() throws Exception {
String base = "path/to/file";

File basedir = new File("target/");

SingleTargetMapping mapping = new SingleTargetMapping(null, "/foo");

Set<File> results = mapping.getTargetFiles(basedir, base + ".cs");

assertTrue(results.isEmpty());
}
}
Loading