diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index b5a89511b1..8ee09a01ce 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -843,6 +843,10 @@ Cyril Martin (mcoolive@github.com) does not provide "Type(Type(null))" (2.9.9) -Daniil Barvitsky (dbarvitsky@github( +Daniil Barvitsky (dbarvitsky@github) * Reported #2324: `StringCollectionDeserializer` fails with custom collection (2.9.9) + +Edgar Asatryan (nstdio@github) + * Reported #2374: `ObjectMapper. getRegisteredModuleIds()` throws NPE if no modules registered + (2.9.9.1) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index fc309ce37c..742e6121cd 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -8,6 +8,8 @@ Project: jackson-databind #2326: Block one more gadget type (CVE-2019-12384) #2341: Block one more gadget type (CVE-2019-12814) +#2374: `ObjectMapper. getRegisteredModuleIds()` throws NPE if no modules registered + (reported by Edgar A) 2.9.9 (16-May-2019) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index adfb09b496..f4e571def0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -962,7 +962,8 @@ public ObjectMapper registerModules(Iterable modules) */ public Set getRegisteredModuleIds() { - return Collections.unmodifiableSet(_registeredModuleTypes); + return (_registeredModuleTypes == null) ? + Collections.emptySet() : Collections.unmodifiableSet(_registeredModuleTypes); } /** diff --git a/src/test/java/com/fasterxml/jackson/databind/module/SimpleModuleTest.java b/src/test/java/com/fasterxml/jackson/databind/module/SimpleModuleTest.java index 40a189e69d..da9e7dc7e4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/SimpleModuleTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/SimpleModuleTest.java @@ -319,6 +319,7 @@ public void testGetRegisteredModules() AnotherSimpleModule mod2 = new AnotherSimpleModule("test2", Version.unknownVersion()); ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(mod1); mapper.registerModule(mod2); @@ -326,6 +327,10 @@ public void testGetRegisteredModules() assertEquals(2, registeredModuleIds.size()); assertTrue(registeredModuleIds.contains(mod1.getTypeId())); assertTrue(registeredModuleIds.contains(mod2.getTypeId())); + + // 01-Jul-2019, [databind#2374]: verify empty list is fine + mapper = new ObjectMapper(); + assertEquals(0, mapper.getRegisteredModuleIds().size()); } /*