IDEA-330383 fix before listener in RegistryValue

Close https://github.com/JetBrains/intellij-community/pull/2563

GitOrigin-RevId: fb6870432593141083c59714504a7d9567f0d4f7
This commit is contained in:
Jacob Logsdon
2023-09-04 08:14:34 +00:00
committed by intellij-monorepo-bot
parent 6a7ea7df0c
commit 3a08ca3f08
2 changed files with 17 additions and 19 deletions
@@ -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 + '\'');
@@ -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<String, String> map){
Element registryElement = new Element("registry");