From d45ed056ecbab42be6ae574ad4d65b279f543a99 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 8 Feb 2017 13:44:45 +0100 Subject: [PATCH] clear values cached in StandardFileSystems class when application changes --- .../application/CachedSingletonsRegistry.java | 15 ++++++++- .../openapi/vfs/StandardFileSystems.java | 33 +++++++++++-------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/application/CachedSingletonsRegistry.java b/platform/core-api/src/com/intellij/openapi/application/CachedSingletonsRegistry.java index 7a9b73138a0f..ed62c5ee5b89 100644 --- a/platform/core-api/src/com/intellij/openapi/application/CachedSingletonsRegistry.java +++ b/platform/core-api/src/com/intellij/openapi/application/CachedSingletonsRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ */ package com.intellij.openapi.application; +import com.intellij.openapi.util.ClearableLazyValue; import com.intellij.util.ReflectionUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,6 +30,7 @@ import java.util.List; public class CachedSingletonsRegistry { private static final Object LOCK = new CachedSingletonsRegistry(); private static final List> ourRegisteredClasses = new ArrayList>(); + private static final List> ourRegisteredLazyValues = new ArrayList>(); private CachedSingletonsRegistry() {} @@ -40,6 +42,14 @@ public class CachedSingletonsRegistry { return null; } + @NotNull + public static ClearableLazyValue markLazyValue(@NotNull ClearableLazyValue lazyValue) { + synchronized (LOCK) { + ourRegisteredLazyValues.add(lazyValue); + } + return lazyValue; + } + public static void cleanupCachedFields() { synchronized (LOCK) { for (Class aClass : ourRegisteredClasses) { @@ -50,6 +60,9 @@ public class CachedSingletonsRegistry { // Ignore cleanup failed. In some cases we cannot find ourInstance field if idea.jar is scrambled and names of the private fields changed } } + for (ClearableLazyValue value : ourRegisteredLazyValues) { + value.drop(); + } } } diff --git a/platform/core-api/src/com/intellij/openapi/vfs/StandardFileSystems.java b/platform/core-api/src/com/intellij/openapi/vfs/StandardFileSystems.java index 3997b6b7fbb0..d7e5cd2959f0 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/StandardFileSystems.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/StandardFileSystems.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,8 @@ */ package com.intellij.openapi.vfs; -import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.openapi.application.CachedSingletonsRegistry; +import com.intellij.openapi.util.ClearableLazyValue; import com.intellij.util.io.URLUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,21 +31,25 @@ public class StandardFileSystems { public static final String JRT_PROTOCOL = "jrt"; public static final String JRT_PROTOCOL_PREFIX = JRT_PROTOCOL + URLUtil.SCHEME_SEPARATOR; - private static final NotNullLazyValue ourLocal = new NotNullLazyValue() { - @NotNull - @Override - protected VirtualFileSystem compute() { - return VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL); + private static final ClearableLazyValue ourLocal = CachedSingletonsRegistry.markLazyValue( + new ClearableLazyValue() { + @NotNull + @Override + protected VirtualFileSystem compute() { + return VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL); + } } - }; + ); - private static final NotNullLazyValue ourJar = new NotNullLazyValue() { - @NotNull - @Override - protected VirtualFileSystem compute() { - return VirtualFileManager.getInstance().getFileSystem(JAR_PROTOCOL); + private static final ClearableLazyValue ourJar = CachedSingletonsRegistry.markLazyValue( + new ClearableLazyValue() { + @NotNull + @Override + protected VirtualFileSystem compute() { + return VirtualFileManager.getInstance().getFileSystem(JAR_PROTOCOL); + } } - }; + ); public static VirtualFileSystem local() { return ourLocal.getValue();