diff --git a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java index 47b9755eee62..7149d621c237 100644 --- a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java +++ b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java @@ -246,14 +246,12 @@ public class RegistryValue { } public void setValue(String value) { - resetCache(); - RegistryValueListener globalValueChangeListener = myRegistry.getValueChangeListener(); globalValueChangeListener.beforeValueChanged(this); for (RegistryValueListener each : myListeners) { each.beforeValueChanged(this); } - + resetCache(); myRegistry.getUserProperties().put(myKey, value); LOG.info("Registry value '" + myKey + "' has changed to '" + value + '\''); diff --git a/platform/util/testSrc/com/intellij/openapi/util/registry/RegistryTest.java b/platform/util/testSrc/com/intellij/openapi/util/registry/RegistryTest.java index c2ca5bf99393..654bd20a0b6c 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/registry/RegistryTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/registry/RegistryTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.util.registry; import com.intellij.idea.TestFor; @@ -21,7 +7,6 @@ import com.intellij.openapi.util.Pair; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.junit.After; -import org.junit.Before; import org.junit.Test; import java.util.ArrayList; @@ -197,6 +182,21 @@ public class RegistryTest { ); } + @Test + public void beforeListenerDoesNotChangeValueWhenSetting() { + String registryValue = "testBoolean"; + RegistryValue regValue = new RegistryValue(Registry.getInstance(), registryValue, null); + regValue.setValue(false); + Registry.setValueChangeListener(new RegistryValueListener() { + @Override + public void beforeValueChanged(@NotNull RegistryValue value) { + regValue.asBoolean(); + } + }); + regValue.setValue(true); + assertTrue(regValue.asBoolean()); + } + private Element registryElementFromMap(Map map){ Element registryElement = new Element("registry");