[vfs] IDEA-331415: exception for illegal urls

+ throw exception on urls like 'Z:' instead of logging a warning -- such urls shouldn't get to the VFS, but some time ago they somehow sneaked in, so we were forced to deal with them temporary -> hopefully, now they are gone, so we could protect VFS from them

GitOrigin-RevId: 73ab84df3c7f7a26538e463419a9c41ca6fd6387
This commit is contained in:
Ruslan Cheremin
2025-06-14 11:29:52 +00:00
committed by intellij-monorepo-bot
parent cd9c207341
commit 355a7d91cf
2 changed files with 18 additions and 13 deletions
@@ -1871,12 +1871,10 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable {
if (rootUrl.endsWith(":")) {
if (OSAgnosticPathUtil.startsWithWindowsDrive(rootUrl) && rootUrl.length() == 2) {
//Workaround for IDEA-331415: it shouldn't happen: rootUrl must be an url (even though sometimes not
// fully correct URL), not a win-path -- but it sometimes happens, even though shouldn't:
LOG.warn("detectFileSystem[root url='" + rootUrl + "', path='" + rootPath + "']: root URL is not an URL, but Win drive path");
return LocalFileSystem.getInstance();
//TODO RC: I hope this was just a fluck -- i.e. some VFS instances somehow got 'infected' by these wrong
// root urls, but they wash off with time -- and the need for this branch disappears. Lets replace the
// workaround with an AssertionError in v24.1, and see.
// fully correct URL), not a win-path -- but it sometimes happens, even though shouldn't.
// I hope this was just a temporary fluck -- i.e. some VFS instances somehow got 'infected' by these
// wrong root urls, but they wash off with time -- and the need for this branch disappears.
throw new IllegalArgumentException("detectFileSystem[root url='" + rootUrl + "', path='" + rootPath + "']: root URL is not an URL, but Win drive path");
}
//We truncated all trailing '/' in the .findRoot(), before putting rootUrl into FSRecords.findOrCreateRoot()
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.vfs.newvfs.persistent;
import com.intellij.openapi.vfs.JarFileSystem;
@@ -7,7 +7,8 @@ import com.intellij.openapi.vfs.ex.temp.TempFileSystem;
import com.intellij.testFramework.junit5.TestApplication;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
/** Specific tests for VFS roots behavior */
@TestApplication
@@ -16,11 +17,6 @@ public class PersistentFS_Roots_Test {
@Test
void detectFileSystem_CorrectlyDetectsFileSystems_ForFewCommonlyUsedUrls() {
assertSame(
PersistentFSImpl.detectFileSystem("Z:", "Z:"),
LocalFileSystem.getInstance(),
"Special case: workaround for IDEA-331415 -- likely to be removed after VFS become protected of such roots"
);
assertSame(
PersistentFSImpl.detectFileSystem("file://Z:", "Z:"),
LocalFileSystem.getInstance()
@@ -45,4 +41,15 @@ public class PersistentFS_Roots_Test {
);
}
@Test//IDEA-331415
void detectFileSystem_FailsOnIncorrectUrl() {
try {
PersistentFSImpl.detectFileSystem("Z:", "Z:");
fail("Windows drive is not a valid URL -> should fail");
}
catch (IllegalArgumentException e) {
//Special case (IDEA-331415): Windows drive is not a valid URL
}
}
}