From e61da278ba28265c6a0ae0e66e37c515f1e397d1 Mon Sep 17 00:00:00 2001 From: vramik Date: Tue, 14 Dec 2021 17:16:01 +0100 Subject: [PATCH] When ternary conditional operator uses primitive type it could throw NPE in some cases Closes #9137 --- .../models/cache/infinispan/entities/CachedRealm.java | 6 +++--- .../sessions/infinispan/changes/SessionEntityWrapper.java | 2 +- .../cluster/infinispan/ConcurrencyJDGCachePutTest.java | 2 +- .../java/org/keycloak/component/ComponentModelScope.java | 6 +++--- .../org/keycloak/policy/DigitsPasswordPolicyProvider.java | 2 +- .../policy/ForceExpiredPasswordPolicyProviderFactory.java | 4 ++-- .../main/java/org/keycloak/component/ComponentModel.java | 6 +++--- .../src/main/java/org/keycloak/models/RealmModel.java | 6 +++--- .../java/org/keycloak/policy/PasswordPolicyProvider.java | 2 +- .../endpoints/request/AuthzEndpointQueryStringParser.java | 2 +- .../endpoints/request/AuthzEndpointRequestObjectParser.java | 2 +- .../BackchannelAuthenticationEndpointRequestBodyParser.java | 2 +- ...ackchannelAuthenticationEndpointSignedRequestParser.java | 2 +- .../oidc/par/endpoints/request/AuthzEndpointParParser.java | 2 +- .../java/org/keycloak/services/util/JsonConfigProvider.java | 6 +++--- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java index 009f644ee0..d491622717 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedRealm.java @@ -725,17 +725,17 @@ public class CachedRealm extends AbstractExtendableRevisioned { public Integer getAttribute(String name, Integer defaultValue) { String v = getAttribute(name); - return v != null ? Integer.parseInt(v) : defaultValue; + return v != null ? Integer.valueOf(v) : defaultValue; } public Long getAttribute(String name, Long defaultValue) { String v = getAttribute(name); - return v != null ? Long.parseLong(v) : defaultValue; + return v != null ? Long.valueOf(v) : defaultValue; } public Boolean getAttribute(String name, Boolean defaultValue) { String v = getAttribute(name); - return v != null ? Boolean.parseBoolean(v) : defaultValue; + return v != null ? Boolean.valueOf(v) : defaultValue; } public Map getAttributes() { diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java index fd6ebc0385..040933be62 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/SessionEntityWrapper.java @@ -112,7 +112,7 @@ public class SessionEntityWrapper { public Integer getLocalMetadataNoteInt(String key) { String note = getLocalMetadataNote(key); - return note==null ? null : Integer.parseInt(note); + return note==null ? null : Integer.valueOf(note); } public void putLocalMetadataNoteInt(String key, int value) { diff --git a/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/ConcurrencyJDGCachePutTest.java b/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/ConcurrencyJDGCachePutTest.java index bd8efd07cc..6e537e526c 100644 --- a/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/ConcurrencyJDGCachePutTest.java +++ b/model/infinispan/src/test/java/org/keycloak/cluster/infinispan/ConcurrencyJDGCachePutTest.java @@ -165,7 +165,7 @@ public class ConcurrencyJDGCachePutTest { } public static int getClusterStartupTime(Cache cache, String cacheKey, EntryInfo wrapper, int myThreadId) { - Integer startupTime = myThreadId==1 ? Integer.parseInt(cacheKey.substring(4)) : Integer.parseInt(cacheKey.substring(4)) * 2; + Integer startupTime = myThreadId==1 ? Integer.valueOf(cacheKey.substring(4)) : Integer.valueOf(cacheKey.substring(4)) * 2; // Concurrency doesn't work correctly with this //Integer existingClusterStartTime = (Integer) cache.putIfAbsent(cacheKey, startupTime); diff --git a/server-spi-private/src/main/java/org/keycloak/component/ComponentModelScope.java b/server-spi-private/src/main/java/org/keycloak/component/ComponentModelScope.java index 4d225a86bc..43a0945dcf 100644 --- a/server-spi-private/src/main/java/org/keycloak/component/ComponentModelScope.java +++ b/server-spi-private/src/main/java/org/keycloak/component/ComponentModelScope.java @@ -84,7 +84,7 @@ public class ComponentModelScope implements Scope { @Override public Integer getInt(String key, Integer defaultValue) { final String res = componentConfig.get(prefix + key, null); - return (res == null) ? origScope.getInt(key, defaultValue) : Integer.parseInt(res); + return (res == null) ? origScope.getInt(key, defaultValue) : Integer.valueOf(res); } @Override @@ -95,7 +95,7 @@ public class ComponentModelScope implements Scope { @Override public Long getLong(String key, Long defaultValue) { final String res = componentConfig.get(prefix + key, null); - return (res == null) ? origScope.getLong(key, defaultValue) : Long.parseLong(res); + return (res == null) ? origScope.getLong(key, defaultValue) : Long.valueOf(res); } @Override @@ -106,7 +106,7 @@ public class ComponentModelScope implements Scope { @Override public Boolean getBoolean(String key, Boolean defaultValue) { final String res = componentConfig.get(prefix + key, null); - return (res == null) ? origScope.getBoolean(key, defaultValue) : Boolean.parseBoolean(res); + return (res == null) ? origScope.getBoolean(key, defaultValue) : Boolean.valueOf(res); } @Override diff --git a/server-spi-private/src/main/java/org/keycloak/policy/DigitsPasswordPolicyProvider.java b/server-spi-private/src/main/java/org/keycloak/policy/DigitsPasswordPolicyProvider.java index 391317ed9b..bd47144daa 100644 --- a/server-spi-private/src/main/java/org/keycloak/policy/DigitsPasswordPolicyProvider.java +++ b/server-spi-private/src/main/java/org/keycloak/policy/DigitsPasswordPolicyProvider.java @@ -53,7 +53,7 @@ public class DigitsPasswordPolicyProvider implements PasswordPolicyProvider { @Override public Object parseConfig(String value) { - return value != null ? Integer.parseInt(value) : 1; + return value != null ? Integer.valueOf(value) : Integer.valueOf(1); } @Override diff --git a/server-spi-private/src/main/java/org/keycloak/policy/ForceExpiredPasswordPolicyProviderFactory.java b/server-spi-private/src/main/java/org/keycloak/policy/ForceExpiredPasswordPolicyProviderFactory.java index b9f6f4ce41..8f39b75956 100644 --- a/server-spi-private/src/main/java/org/keycloak/policy/ForceExpiredPasswordPolicyProviderFactory.java +++ b/server-spi-private/src/main/java/org/keycloak/policy/ForceExpiredPasswordPolicyProviderFactory.java @@ -29,7 +29,7 @@ import org.keycloak.models.UserModel; */ public class ForceExpiredPasswordPolicyProviderFactory implements PasswordPolicyProviderFactory, PasswordPolicyProvider { - public static final int DEFAULT_VALUE = 365; + public static final Integer DEFAULT_VALUE = 365; @Override public PasswordPolicyProvider create(KeycloakSession session) { @@ -85,7 +85,7 @@ public class ForceExpiredPasswordPolicyProviderFactory implements PasswordPolicy @Override public Object parseConfig(String value) { - return value != null ? Integer.parseInt(value) : DEFAULT_VALUE; + return value != null ? Integer.valueOf(value) : DEFAULT_VALUE; } } diff --git a/server-spi/src/main/java/org/keycloak/component/ComponentModel.java b/server-spi/src/main/java/org/keycloak/component/ComponentModel.java index abdb481ec8..55b42d7c24 100755 --- a/server-spi/src/main/java/org/keycloak/component/ComponentModel.java +++ b/server-spi/src/main/java/org/keycloak/component/ComponentModel.java @@ -91,17 +91,17 @@ public class ComponentModel implements Serializable { public int get(String key, int defaultValue) { String s = get(key); - return s != null ? Integer.parseInt(s) : defaultValue; + return s != null ? Integer.valueOf(s) : defaultValue; } public long get(String key, long defaultValue) { String s = get(key); - return s != null ? Long.parseLong(s) : defaultValue; + return s != null ? Long.valueOf(s) : defaultValue; } public boolean get(String key, boolean defaultValue) { String s = get(key); - return s != null ? Boolean.parseBoolean(s) : defaultValue; + return s != null ? Boolean.valueOf(s) : defaultValue; } public void put(String key, String value) { diff --git a/server-spi/src/main/java/org/keycloak/models/RealmModel.java b/server-spi/src/main/java/org/keycloak/models/RealmModel.java index 087b14024c..a2999583c9 100755 --- a/server-spi/src/main/java/org/keycloak/models/RealmModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RealmModel.java @@ -143,15 +143,15 @@ public interface RealmModel extends RoleContainerModel { String getAttribute(String name); default Integer getAttribute(String name, Integer defaultValue) { String v = getAttribute(name); - return v != null ? Integer.parseInt(v) : defaultValue; + return v != null ? Integer.valueOf(v) : defaultValue; } default Long getAttribute(String name, Long defaultValue) { String v = getAttribute(name); - return v != null ? Long.parseLong(v) : defaultValue; + return v != null ? Long.valueOf(v) : defaultValue; } default Boolean getAttribute(String name, Boolean defaultValue) { String v = getAttribute(name); - return v != null ? Boolean.parseBoolean(v) : defaultValue; + return v != null ? Boolean.valueOf(v) : defaultValue; } Map getAttributes(); diff --git a/server-spi/src/main/java/org/keycloak/policy/PasswordPolicyProvider.java b/server-spi/src/main/java/org/keycloak/policy/PasswordPolicyProvider.java index 5d54251dfd..2bfd51b151 100644 --- a/server-spi/src/main/java/org/keycloak/policy/PasswordPolicyProvider.java +++ b/server-spi/src/main/java/org/keycloak/policy/PasswordPolicyProvider.java @@ -35,7 +35,7 @@ public interface PasswordPolicyProvider extends Provider { default Integer parseInteger(String value, Integer defaultValue) { try { - return value != null ? Integer.parseInt(value) : defaultValue; + return value != null ? Integer.valueOf(value) : defaultValue; } catch (NumberFormatException e) { throw new PasswordPolicyConfigException("Not a valid number"); } diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointQueryStringParser.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointQueryStringParser.java index cde8233a56..ddb60ea50d 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointQueryStringParser.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointQueryStringParser.java @@ -46,7 +46,7 @@ class AuthzEndpointQueryStringParser extends AuthzEndpointRequestParser { protected Integer getIntParameter(String paramName) { checkDuplicated(requestParams, paramName); String paramVal = requestParams.getFirst(paramName); - return paramVal==null ? null : Integer.parseInt(paramVal); + return paramVal==null ? null : Integer.valueOf(paramVal); } public String getInvalidRequestMessage() { diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestObjectParser.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestObjectParser.java index 28fcf9a95d..231e14b239 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestObjectParser.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestObjectParser.java @@ -81,7 +81,7 @@ public class AuthzEndpointRequestObjectParser extends AuthzEndpointRequestParser @Override protected Integer getIntParameter(String paramName) { Object val = this.requestParams.get(paramName); - return val==null ? null : Integer.parseInt(getParameter(paramName)); + return val==null ? null : Integer.valueOf(getParameter(paramName)); } @Override diff --git a/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointRequestBodyParser.java b/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointRequestBodyParser.java index ee0673850d..6c95c4d66c 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointRequestBodyParser.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointRequestBodyParser.java @@ -46,7 +46,7 @@ class BackchannelAuthenticationEndpointRequestBodyParser extends BackchannelAuth protected Integer getIntParameter(String paramName) { checkDuplicated(requestParams, paramName); String paramVal = requestParams.getFirst(paramName); - return paramVal==null ? null : Integer.parseInt(paramVal); + return paramVal==null ? null : Integer.valueOf(paramVal); } public String getInvalidRequestMessage() { diff --git a/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointSignedRequestParser.java b/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointSignedRequestParser.java index dba3544f00..4baef290d4 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointSignedRequestParser.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/grants/ciba/endpoints/request/BackchannelAuthenticationEndpointSignedRequestParser.java @@ -95,7 +95,7 @@ class BackchannelAuthenticationEndpointSignedRequestParser extends BackchannelAu @Override protected Integer getIntParameter(String paramName) { Object val = this.requestParams.get(paramName); - return val==null ? null : Integer.parseInt(getParameter(paramName)); + return val==null ? null : Integer.valueOf(getParameter(paramName)); } @Override diff --git a/services/src/main/java/org/keycloak/protocol/oidc/par/endpoints/request/AuthzEndpointParParser.java b/services/src/main/java/org/keycloak/protocol/oidc/par/endpoints/request/AuthzEndpointParParser.java index 10dceb1627..a19f696165 100644 --- a/services/src/main/java/org/keycloak/protocol/oidc/par/endpoints/request/AuthzEndpointParParser.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/par/endpoints/request/AuthzEndpointParParser.java @@ -95,7 +95,7 @@ public class AuthzEndpointParParser extends AuthzEndpointRequestParser { @Override protected Integer getIntParameter(String paramName) { String paramVal = requestParams.get(paramName); - return paramVal == null ? null : Integer.parseInt(paramVal); + return paramVal == null ? null : Integer.valueOf(paramVal); } public String getInvalidRequestMessage() { diff --git a/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java b/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java index e875aea12b..63cf394a0e 100755 --- a/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java +++ b/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java @@ -129,7 +129,7 @@ public class JsonConfigProvider implements Config.ConfigProvider { } if (n.isTextual()) { String v = replaceProperties(n.textValue()); - return !v.isEmpty() ? Integer.parseInt(v) : defaultValue; + return !v.isEmpty() ? Integer.valueOf(v) : defaultValue; } else { return n.intValue(); } @@ -151,7 +151,7 @@ public class JsonConfigProvider implements Config.ConfigProvider { } if (n.isTextual()) { String v = replaceProperties(n.textValue()); - return !v.isEmpty() ? Long.parseLong(v) : defaultValue; + return !v.isEmpty() ? Long.valueOf(v) : defaultValue; } else { return n.longValue(); } @@ -173,7 +173,7 @@ public class JsonConfigProvider implements Config.ConfigProvider { } if (n.isTextual()) { String v = replaceProperties(n.textValue()); - return !v.isEmpty() ? Boolean.parseBoolean(v) : defaultValue; + return !v.isEmpty() ? Boolean.valueOf(v) : defaultValue; } else { return n.booleanValue(); }