Skip to content

Commit 2654026

Browse files
committed
[bugfix] Avoid NPE with JDK 17 when calling Paths.get(null, ...)
1 parent 2719466 commit 2654026

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

exist-core/src/main/java/org/exist/source/SourceFactory.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class SourceFactory {
7575
* but the calling user does not have permission to access it.
7676
* @throws IOException if a general I/O error occurs whilst accessing the resource.
7777
*/
78-
public static @Nullable Source getSource(final DBBroker broker, final String contextPath, final String location, final boolean checkXQEncoding) throws IOException, PermissionDeniedException {
78+
public static @Nullable Source getSource(final DBBroker broker, @Nullable final String contextPath, final String location, final boolean checkXQEncoding) throws IOException, PermissionDeniedException {
7979
Source source = null;
8080

8181
/* resource: */
@@ -212,12 +212,18 @@ private static Source getSource_fromClasspath(final String contextPath, final St
212212
*
213213
* @return the source, or null if there is no such resource in the db indicated by {@code path}.
214214
*/
215-
private static @Nullable Source getSource_fromFile(final String contextPath, final String location, final boolean checkXQEncoding) {
215+
private static @Nullable Source getSource_fromFile(@Nullable final String contextPath, final String location, final boolean checkXQEncoding) {
216216
String locationPath = location.replaceAll("^(file:)?/*(.*)$", "$2");
217217

218218
Source source = null;
219219
try {
220-
final Path p = Paths.get(contextPath, locationPath);
220+
final Path p;
221+
if (contextPath == null) {
222+
p = Paths.get(locationPath);
223+
} else {
224+
p = Paths.get(contextPath, locationPath);
225+
}
226+
221227
if (Files.isReadable(p)) {
222228
locationPath = p.toUri().toASCIIString();
223229
source = new FileSource(p, checkXQEncoding);

0 commit comments

Comments
 (0)