Skip to content

Commit

Permalink
fix(mpconfig): do not throw NPE when profiled setting only payara#6954
Browse files Browse the repository at this point in the history
Also simplifies the check in case of a same ordinal value source is
around. Left comments and extended unit test to make sure the desired
behaviour is tested.
  • Loading branch information
poikilotherm committed Jan 31, 2024
1 parent 1f695b8 commit 9baaeb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ private ConfigValueImpl resolve(String propertyName, String propertyDefault, boo

if(profile != null && result != null) {
ConfigValueImpl resultWithoutProfile = getValue(resolveExpression(propertyName));
result = resultWithoutProfile.getSourceOrdinal() == result.getSourceOrdinal() ? result :
(resultWithoutProfile.getSourceOrdinal() > result.getSourceOrdinal()) ? resultWithoutProfile : result;
// Note: In case there is a non-profiled value from a source with the same ordinal value, it will be ignored.
// All spec versions including v3.1 do not include a definition for this edge case -
// all sources are supposed to have a unique ordinal value.
if (resultWithoutProfile != null && resultWithoutProfile.getSourceOrdinal() > result.getSourceOrdinal()) {
result = resultWithoutProfile;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Set;

Expand All @@ -57,8 +56,10 @@
public class ConfigExpressionResolverTest {

private final ConfigSource source = createSource("S1", 100, new HashMap<>());
private final ConfigSource source2 = createSource("S2", 110, new HashMap<>());
private final ConfigExpressionResolver resolver = new ConfigExpressionResolver(Set.of(source, source2), "test");
private final ConfigSource sourceHigherOrdinal = createSource("SHO", 110, new HashMap<>());
private final ConfigSource sourceEqualOrdinal = createSource("SEO", 100, new HashMap<>());
private final ConfigSource sourceLowerOrdinal = createSource("SEO", 90, new HashMap<>());
private final ConfigExpressionResolver resolver = new ConfigExpressionResolver(Set.of(source, sourceHigherOrdinal, sourceEqualOrdinal, sourceLowerOrdinal), "test");

@Before
public void configureConfigProperties() {
Expand All @@ -79,8 +80,11 @@ public void configureConfigProperties() {
source.getProperties().put("fish.payara.badger", "badger");
source.getProperties().put("%test.fish.payara.rod", "bites");

source2.getProperties().put("fish.payara.rod", "nobites");
source2.getProperties().put("%test.fish.payara.profile-only", "gotcha");
sourceHigherOrdinal.getProperties().put("fish.payara.rod", "nobites");
sourceHigherOrdinal.getProperties().put("%test.fish.payara.profile-only", "gotcha");

sourceEqualOrdinal.getProperties().put("fish.payara.badger", "i-shall-be-ignored");
sourceLowerOrdinal.getProperties().put("fish.payara.badger", "i-shall-be-ignored");
}

@Test
Expand Down Expand Up @@ -187,6 +191,8 @@ public void testExpressionExpansionDisabled() {

@Test
public void testProfiles() {
// This test case does not only test if the profiled value is used from the same source, but also if the
// defined equal and lower ordinal sources are ignored
ConfigValue result = resolver.resolve("fish.payara.badger");
assertEquals("mushroom", result.getValue());
assertEquals("mushroom", result.getRawValue());
Expand Down

0 comments on commit 9baaeb8

Please sign in to comment.