ConfigManager: Fix NPE when resetting configs with null default
This commit is contained in:
@@ -659,6 +659,7 @@ public class ConfigManager
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
static String objectToString(Object object)
|
static String objectToString(Object object)
|
||||||
{
|
{
|
||||||
if (object instanceof Color)
|
if (object instanceof Color)
|
||||||
@@ -702,7 +703,7 @@ public class ConfigManager
|
|||||||
{
|
{
|
||||||
return Long.toString(((Duration) object).toMillis());
|
return Long.toString(((Duration) object).toMillis());
|
||||||
}
|
}
|
||||||
return object.toString();
|
return object == null ? null : object.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(priority = 100)
|
@Subscribe(priority = 100)
|
||||||
|
|||||||
@@ -118,6 +118,18 @@ public class ConfigManagerTest
|
|||||||
|
|
||||||
TestConfig conf = manager.getConfig(TestConfig.class);
|
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||||
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);
|
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);
|
||||||
Assert.assertEquals(1, descriptor.getItems().size());
|
Assert.assertEquals(2, descriptor.getItems().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResetNullDefaultConfig()
|
||||||
|
{
|
||||||
|
TestConfig conf = manager.getConfig(TestConfig.class);
|
||||||
|
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);
|
||||||
|
conf.nullDefaultKey("new value");
|
||||||
|
|
||||||
|
manager.unsetConfiguration(descriptor.getGroup().value(), "nullDefaultKey");
|
||||||
|
manager.setDefaultConfiguration(conf, false);
|
||||||
|
Assert.assertNull(conf.nullDefaultKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,21 @@ public interface TestConfig extends Config
|
|||||||
description = "value"
|
description = "value"
|
||||||
)
|
)
|
||||||
void key(String key);
|
void key(String key);
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "nullDefaultKey",
|
||||||
|
name = "Key Name",
|
||||||
|
description = "value"
|
||||||
|
)
|
||||||
|
void nullDefaultKey(String key);
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "nullDefaultKey",
|
||||||
|
name = "Key Name",
|
||||||
|
description = "value"
|
||||||
|
)
|
||||||
|
default String nullDefaultKey()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user