From d63be20d7c27c9ab48f1145fcea045eddd566e36 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 12 Mar 2020 14:10:27 +0300 Subject: [PATCH] Tolerate file/directory entry with the same name in .jar file to fix IDEA-227977 Project under network mount doesn't open anymore after upgrade to 2019.3 GitOrigin-RevId: 217830687336e2c41864e4d2deeaad171b0916c9 --- java/java-tests/testData/vfs/sample.jar | Bin 0 -> 450 bytes .../openapi/vfs/impl/ZipHandlerBase.java | 3 ++- .../openapi/vfs/local/JarFileSystemTest.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/vfs/sample.jar diff --git a/java/java-tests/testData/vfs/sample.jar b/java/java-tests/testData/vfs/sample.jar new file mode 100644 index 0000000000000000000000000000000000000000..acbe629b519d39b9e2fa89809feabdb714236ff2 GIT binary patch literal 450 zcmWIWW@Zs#;Nak3=n~5gU_b)Q3@i-E`MLj2F)%PQ1bDM^faI8<3IcFy69B5v2kO)J zNX^N~*GtYxEH1X~+v|7OL7*l5Z@0eM#tLSu1rMZlEijoFz{Slq;rC|CgOTa;pIGb( zU*)0siNQuBsn+F<*W$VU#+T~;%lI?M1#qDzo&5#i}!U*$h7%_}v2B*j>7&ik>b(KJzgFZ-k2%o*q18>X0kG&sVV{ZHJ1 z?cr literal 0 HcmV?d00001 diff --git a/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipHandlerBase.java b/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipHandlerBase.java index b250d3ff26d5..94991d5b9238 100644 --- a/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipHandlerBase.java +++ b/platform/core-impl/src/com/intellij/openapi/vfs/impl/ZipHandlerBase.java @@ -50,7 +50,7 @@ public abstract class ZipHandlerBase extends ArchiveHandler { } @NotNull - protected Map buildEntryMapForZipFile(ZipFile zip) { + protected Map buildEntryMapForZipFile(@NotNull ZipFile zip) { Map map = new ZipEntryMap(zip.size()); map.put("", createRootEntry()); @@ -80,6 +80,7 @@ public abstract class ZipHandlerBase extends ArchiveHandler { EntryInfo info = map.get(entryName); if (info != null) return info; + entryName = StringUtil.trimStart(entryName, "/"); Trinity path = splitPathAndFix(entryName); EntryInfo parentInfo = getOrCreate(path.first, map, zip); if (".".equals(path.second)) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java index 7bf992a9cbbf..701e360f1c46 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java @@ -3,6 +3,7 @@ package com.intellij.openapi.vfs.local; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileAttributes; import com.intellij.openapi.util.io.FileUtil; @@ -17,6 +18,7 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; import com.intellij.testFramework.rules.TempDirectory; import com.intellij.util.containers.ContainerUtil; @@ -297,6 +299,19 @@ public class JarFileSystemTest extends BareTestFixtureTestCase { } } + @Test + public void testCrazyJarWithDuplicateEntriesMustNotCrashAnything() { + String jarPath = PathManagerEx.getTestDataPath() + "/vfs/sample.jar"; + VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(jarPath); + assertNotNull(vFile); + + VirtualFile jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile); + assertNotNull(jarRoot); + String[] children = JarFileSystem.getInstance().list(jarRoot); + assertEquals("com", UsefulTestCase.assertOneElement(children)); + assertEquals("Hello.class", UsefulTestCase.assertOneElement(JarFileSystem.getInstance().list(jarRoot.findFileByRelativePath("com")))); + } + @NotNull private static VirtualFile findByPath(String path) { VirtualFile file = JarFileSystem.getInstance().findFileByPath(path);