From 355a7d91cfe7f8a8d0684e0d432cafebc3454749 Mon Sep 17 00:00:00 2001 From: Ruslan Cheremin Date: Sat, 14 Jun 2025 11:43:47 +0200 Subject: [PATCH] [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 --- .../newvfs/persistent/PersistentFSImpl.java | 10 ++++----- .../persistent/PersistentFS_Roots_Test.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 8987ece83f09..9f05c61e158a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -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() diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS_Roots_Test.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS_Roots_Test.java index 7ddd9a4ca2ca..d4ce503b480c 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS_Roots_Test.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/newvfs/persistent/PersistentFS_Roots_Test.java @@ -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 + } + } }