Skip to content

Commit d435b82

Browse files
author
Vladimir Kotal
authored
document and handle InvalidPathException in history parsers (#2057)
fixes #2013
1 parent 53b2196 commit d435b82

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.nio.file.FileSystems;
4545
import java.nio.file.FileVisitResult;
4646
import java.nio.file.Files;
47+
import java.nio.file.InvalidPathException;
4748
import java.nio.file.Path;
4849
import java.nio.file.Paths;
4950
import java.nio.file.SimpleFileVisitor;
@@ -408,9 +409,11 @@ public String getPathRelativeToSourceRoot(File file)
408409
* @throws FileNotFoundException if the file is not relative to source root
409410
* @throws ForbiddenSymlinkException if symbolic-link checking encounters
410411
* an ineligible link
412+
* @throws InvalidPathException if the path cannot be decoded
411413
*/
412414
public String getPathRelativeToSourceRoot(File file, int stripCount)
413-
throws IOException, ForbiddenSymlinkException {
415+
throws IOException, ForbiddenSymlinkException, FileNotFoundException,
416+
InvalidPathException {
414417
String sourceRoot = getSourceRootPath();
415418
if (sourceRoot == null) {
416419
throw new FileNotFoundException("Source Root Not Found");

src/org/opensolaris/opengrok/history/BazaarHistoryParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
32+
import java.nio.file.InvalidPathException;
3233
import java.text.DateFormat;
3334
import java.text.ParseException;
3435
import java.util.ArrayList;
@@ -175,6 +176,8 @@ public void processStream(InputStream input) throws IOException {
175176
} catch (ForbiddenSymlinkException e) {
176177
LOGGER.log(Level.FINER, e.getMessage());
177178
// ignored
179+
} catch (InvalidPathException e) {
180+
LOGGER.log(Level.WARNING, e.getMessage());
178181
}
179182
}
180183
break;

src/org/opensolaris/opengrok/history/GitHistoryParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.io.InputStream;
3232
import java.io.InputStreamReader;
33+
import java.nio.file.InvalidPathException;
3334
import java.text.DateFormat;
3435
import java.text.ParseException;
3536
import java.util.ArrayList;
@@ -139,6 +140,8 @@ private void process(BufferedReader in) throws IOException {
139140
} catch (FileNotFoundException e) { //NOPMD
140141
// If the file is not located under the source root,
141142
// ignore it (bug #11664).
143+
} catch (InvalidPathException e) {
144+
LOGGER.log(Level.WARNING, e.getMessage());
142145
}
143146
}
144147
}

src/org/opensolaris/opengrok/history/MercurialHistoryParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
32+
import java.nio.file.InvalidPathException;
3233
import java.text.DateFormat;
3334
import java.text.ParseException;
3435
import java.util.ArrayList;
@@ -150,6 +151,8 @@ public void processStream(InputStream input) throws IOException {
150151
} catch (FileNotFoundException e) { // NOPMD
151152
// If the file is not located under the source root,
152153
// ignore it (bug #11664).
154+
} catch (InvalidPathException e) {
155+
LOGGER.log(Level.WARNING, e.getMessage());
153156
}
154157
}
155158
}

src/org/opensolaris/opengrok/history/MonotoneHistoryParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
32+
import java.nio.file.InvalidPathException;
3233
import java.text.DateFormat;
3334
import java.text.ParseException;
3435
import java.util.ArrayList;
@@ -174,6 +175,8 @@ public void processStream(InputStream input) throws IOException {
174175
// ignore
175176
} catch (FileNotFoundException e) { // NOPMD
176177
// If the file is not located under the source root, ignore it
178+
} catch (InvalidPathException e) {
179+
LOGGER.log(Level.WARNING, e.getMessage());
177180
}
178181
}
179182
}

src/org/opensolaris/opengrok/util/PathUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.nio.file.Files;
29+
import java.nio.file.InvalidPathException;
2930
import java.nio.file.Paths;
3031
import java.util.Deque;
3132
import java.util.LinkedList;
@@ -94,10 +95,11 @@ public static String getRelativeToCanonical(String path, String canonical)
9495
* for portions of {@code path}
9596
* @throws ForbiddenSymlinkException if symbolic-link checking is active
9697
* and it encounters an ineligible link
98+
* @throws InvalidPathException if path cannot be decoded
9799
*/
98100
public static String getRelativeToCanonical(String path, String canonical,
99101
Set<String> allowedSymlinks)
100-
throws IOException, ForbiddenSymlinkException {
102+
throws IOException, ForbiddenSymlinkException, InvalidPathException {
101103

102104
if (path.equals(canonical)) return "";
103105

0 commit comments

Comments
 (0)