From 78bbaf4b3be61f43bb49ea08cef087a30c13c9f9 Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Thu, 18 Jun 2026 11:25:15 +0200 Subject: [PATCH 1/2] Avoid checking trying to resolve unknown locations As they would right now fall-back to the externel resolver, but in reality we've marked them as invalid, so they should never have successfull IO results --- src/org/rascalmpl/uri/URIResolverRegistry.java | 10 +++++++++- src/org/rascalmpl/uri/URIUtil.java | 4 ---- test/org/rascalmpl/test/repl/JlineParserTest.java | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/org/rascalmpl/uri/URIResolverRegistry.java b/src/org/rascalmpl/uri/URIResolverRegistry.java index 74ed2be4421..a4c447f9480 100644 --- a/src/org/rascalmpl/uri/URIResolverRegistry.java +++ b/src/org/rascalmpl/uri/URIResolverRegistry.java @@ -78,7 +78,6 @@ private URIResolverRegistry() { loadServices(); } - /** * Use with care! This (expensive) reinitialization method clears all caches of all resolvers by * reloading them from scratch. @@ -463,6 +462,9 @@ public void unregisterLogical(String scheme, String auth) { private static final Pattern splitScheme = Pattern.compile("^([^\\+]*)\\+"); private ISourceLocationInput getInputResolver(String scheme) { + if (scheme.equals(URIUtil.unknownLocation().getScheme())) { + return null; + } ISourceLocationInput result = inputResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); @@ -481,6 +483,9 @@ private ISourceLocationInput getInputResolver(String scheme) { } private IClassloaderLocationResolver getClassloaderResolver(String scheme) { + if (scheme.equals(URIUtil.unknownLocation().getScheme())) { + return null; + } IClassloaderLocationResolver result = classloaderResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); @@ -496,6 +501,9 @@ private IClassloaderLocationResolver getClassloaderResolver(String scheme) { } private ISourceLocationOutput getOutputResolver(String scheme) { + if (scheme.equals(URIUtil.unknownLocation().getScheme())) { + return null; + } ISourceLocationOutput result = outputResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); diff --git a/src/org/rascalmpl/uri/URIUtil.java b/src/org/rascalmpl/uri/URIUtil.java index 829001331a5..45b76d98e56 100644 --- a/src/org/rascalmpl/uri/URIUtil.java +++ b/src/org/rascalmpl/uri/URIUtil.java @@ -508,8 +508,4 @@ else if (index != -1) { return URIUtil.changePath(location, path); } - - public static URI invalidURI() { - return rootScheme("invalid"); - } } diff --git a/test/org/rascalmpl/test/repl/JlineParserTest.java b/test/org/rascalmpl/test/repl/JlineParserTest.java index 1b3e9ee9a02..97e1d2ad7a2 100644 --- a/test/org/rascalmpl/test/repl/JlineParserTest.java +++ b/test/org/rascalmpl/test/repl/JlineParserTest.java @@ -16,7 +16,7 @@ private ParsedLine completeParser(String input) { } private ParsedLine completeParser(String input, int cursor) { - var parser = new RascalLineParser(l -> { throw new ParseError("rascal parser not supported in the test yet", URIUtil.invalidURI(), 0, 0, 0, 0, 0, 0); }); + var parser = new RascalLineParser(l -> { throw new ParseError("rascal parser not supported in the test yet", URIUtil.unknownLocation().getURI(), 0, 0, 0, 0, 0, 0); }); return parser.parse(input, cursor, ParseContext.COMPLETE); } From 54096916de17e2f8854a238285b03bd477d2c8e4 Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Thu, 9 Jul 2026 14:35:53 +0200 Subject: [PATCH 2/2] Create resolvers for unsupported features --- .../rascalmpl/uri/URIResolverRegistry.java | 9 -- src/org/rascalmpl/uri/resolvers.config | 2 + .../uri/unsupported/LibraryURIResolver.java | 7 + .../uri/unsupported/UnknownURIResolver.java | 9 ++ .../unsupported/UnsupportedURIResolver.java | 125 ++++++++++++++++++ 5 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 src/org/rascalmpl/uri/unsupported/LibraryURIResolver.java create mode 100644 src/org/rascalmpl/uri/unsupported/UnknownURIResolver.java create mode 100644 src/org/rascalmpl/uri/unsupported/UnsupportedURIResolver.java diff --git a/src/org/rascalmpl/uri/URIResolverRegistry.java b/src/org/rascalmpl/uri/URIResolverRegistry.java index a4c447f9480..68a4ff5bedf 100644 --- a/src/org/rascalmpl/uri/URIResolverRegistry.java +++ b/src/org/rascalmpl/uri/URIResolverRegistry.java @@ -462,9 +462,6 @@ public void unregisterLogical(String scheme, String auth) { private static final Pattern splitScheme = Pattern.compile("^([^\\+]*)\\+"); private ISourceLocationInput getInputResolver(String scheme) { - if (scheme.equals(URIUtil.unknownLocation().getScheme())) { - return null; - } ISourceLocationInput result = inputResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); @@ -483,9 +480,6 @@ private ISourceLocationInput getInputResolver(String scheme) { } private IClassloaderLocationResolver getClassloaderResolver(String scheme) { - if (scheme.equals(URIUtil.unknownLocation().getScheme())) { - return null; - } IClassloaderLocationResolver result = classloaderResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); @@ -501,9 +495,6 @@ private IClassloaderLocationResolver getClassloaderResolver(String scheme) { } private ISourceLocationOutput getOutputResolver(String scheme) { - if (scheme.equals(URIUtil.unknownLocation().getScheme())) { - return null; - } ISourceLocationOutput result = outputResolvers.get(scheme); if (result == null) { Matcher m = splitScheme.matcher(scheme); diff --git a/src/org/rascalmpl/uri/resolvers.config b/src/org/rascalmpl/uri/resolvers.config index 2b599b78ccc..c25d506cf23 100644 --- a/src/org/rascalmpl/uri/resolvers.config +++ b/src/org/rascalmpl/uri/resolvers.config @@ -14,4 +14,6 @@ org.rascalmpl.uri.file.CurrentWorkingDriveResolver org.rascalmpl.uri.file.UNCResolver org.rascalmpl.uri.file.SystemPathURIResolver org.rascalmpl.uri.libraries.MemoryResolver +org.rascalmpl.uri.unsupported.UnknownURIResolver +org.rascalmpl.uri.unsupported.LibraryURIResolver diff --git a/src/org/rascalmpl/uri/unsupported/LibraryURIResolver.java b/src/org/rascalmpl/uri/unsupported/LibraryURIResolver.java new file mode 100644 index 00000000000..458180b73b8 --- /dev/null +++ b/src/org/rascalmpl/uri/unsupported/LibraryURIResolver.java @@ -0,0 +1,7 @@ +package org.rascalmpl.uri.unsupported; + +public class LibraryURIResolver extends UnsupportedURIResolver { + public LibraryURIResolver() { + super("lib", "The lib scheme has been removed, please rewrite to mvn scheme or use getResource"); + } +} diff --git a/src/org/rascalmpl/uri/unsupported/UnknownURIResolver.java b/src/org/rascalmpl/uri/unsupported/UnknownURIResolver.java new file mode 100644 index 00000000000..78013e2489e --- /dev/null +++ b/src/org/rascalmpl/uri/unsupported/UnknownURIResolver.java @@ -0,0 +1,9 @@ +package org.rascalmpl.uri.unsupported; + +import org.rascalmpl.uri.URIUtil; + +public class UnknownURIResolver extends UnsupportedURIResolver { + public UnknownURIResolver() { + super(URIUtil.unknownLocation().getScheme(), "The unknown scheme cannot be read/written to, it indicates someone didn't know the location"); + } +} diff --git a/src/org/rascalmpl/uri/unsupported/UnsupportedURIResolver.java b/src/org/rascalmpl/uri/unsupported/UnsupportedURIResolver.java new file mode 100644 index 00000000000..1914cee3b04 --- /dev/null +++ b/src/org/rascalmpl/uri/unsupported/UnsupportedURIResolver.java @@ -0,0 +1,125 @@ +package org.rascalmpl.uri.unsupported; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.function.Consumer; + +import org.rascalmpl.uri.FileAttributes; +import org.rascalmpl.uri.ISourceLocationInputOutput; +import org.rascalmpl.uri.ISourceLocationWatcher; + +import io.usethesource.vallang.ISourceLocation; + +abstract class UnsupportedURIResolver implements ISourceLocationInputOutput, ISourceLocationWatcher { + + private final String scheme; + private final String message; + + protected UnsupportedURIResolver(String scheme, String message) { + this.scheme = scheme; + this.message = message; + } + + private IOException buildException() { + return new IOException(message); + } + + @Override + public InputStream getInputStream(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public boolean exists(ISourceLocation uri) { + return false; + } + + @Override + public long lastModified(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public long size(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public boolean isDirectory(ISourceLocation uri) { + return false; + } + + @Override + public boolean isFile(ISourceLocation uri) { + return false; + } + + @Override + public boolean isReadable(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public String[] list(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public String scheme() { + return this.scheme; + } + + @Override + public boolean supportsHost() { + return false; + } + + @Override + public FileAttributes stat(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public OutputStream getOutputStream(ISourceLocation uri, boolean append) throws IOException { + throw buildException(); + } + + @Override + public void mkDirectory(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public void remove(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public void setLastModified(ISourceLocation uri, long timestamp) throws IOException { + throw buildException(); + } + + @Override + public boolean isWritable(ISourceLocation uri) throws IOException { + throw buildException(); + } + + @Override + public void watch(ISourceLocation root, Consumer watcher, boolean recursive) + throws IOException { + throw buildException(); + } + + @Override + public void unwatch(ISourceLocation root, Consumer watcher, boolean recursive) + throws IOException { + throw buildException(); + } + + @Override + public boolean supportsRecursiveWatch() { + return false; + } + +}