When ternary conditional operator uses primitive type it could throw NPE in some cases

Closes #9137
This commit is contained in:
vramik 2021-12-14 17:16:01 +01:00 committed by Hynek Mlnařík
parent afeaa6f593
commit e61da278ba
15 changed files with 26 additions and 26 deletions

View file

@ -725,17 +725,17 @@ public class CachedRealm extends AbstractExtendableRevisioned {
public Integer getAttribute(String name, Integer defaultValue) { public Integer getAttribute(String name, Integer defaultValue) {
String v = getAttribute(name); 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) { public Long getAttribute(String name, Long defaultValue) {
String v = getAttribute(name); 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) { public Boolean getAttribute(String name, Boolean defaultValue) {
String v = getAttribute(name); String v = getAttribute(name);
return v != null ? Boolean.parseBoolean(v) : defaultValue; return v != null ? Boolean.valueOf(v) : defaultValue;
} }
public Map<String, String> getAttributes() { public Map<String, String> getAttributes() {

View file

@ -112,7 +112,7 @@ public class SessionEntityWrapper<S extends SessionEntity> {
public Integer getLocalMetadataNoteInt(String key) { public Integer getLocalMetadataNoteInt(String key) {
String note = getLocalMetadataNote(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) { public void putLocalMetadataNoteInt(String key, int value) {

View file

@ -165,7 +165,7 @@ public class ConcurrencyJDGCachePutTest {
} }
public static int getClusterStartupTime(Cache<String, Integer> cache, String cacheKey, EntryInfo wrapper, int myThreadId) { public static int getClusterStartupTime(Cache<String, Integer> 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 // Concurrency doesn't work correctly with this
//Integer existingClusterStartTime = (Integer) cache.putIfAbsent(cacheKey, startupTime); //Integer existingClusterStartTime = (Integer) cache.putIfAbsent(cacheKey, startupTime);

View file

@ -84,7 +84,7 @@ public class ComponentModelScope implements Scope {
@Override @Override
public Integer getInt(String key, Integer defaultValue) { public Integer getInt(String key, Integer defaultValue) {
final String res = componentConfig.get(prefix + key, null); 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 @Override
@ -95,7 +95,7 @@ public class ComponentModelScope implements Scope {
@Override @Override
public Long getLong(String key, Long defaultValue) { public Long getLong(String key, Long defaultValue) {
final String res = componentConfig.get(prefix + key, null); 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 @Override
@ -106,7 +106,7 @@ public class ComponentModelScope implements Scope {
@Override @Override
public Boolean getBoolean(String key, Boolean defaultValue) { public Boolean getBoolean(String key, Boolean defaultValue) {
final String res = componentConfig.get(prefix + key, null); 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 @Override

View file

@ -53,7 +53,7 @@ public class DigitsPasswordPolicyProvider implements PasswordPolicyProvider {
@Override @Override
public Object parseConfig(String value) { public Object parseConfig(String value) {
return value != null ? Integer.parseInt(value) : 1; return value != null ? Integer.valueOf(value) : Integer.valueOf(1);
} }
@Override @Override

View file

@ -29,7 +29,7 @@ import org.keycloak.models.UserModel;
*/ */
public class ForceExpiredPasswordPolicyProviderFactory implements PasswordPolicyProviderFactory, PasswordPolicyProvider { public class ForceExpiredPasswordPolicyProviderFactory implements PasswordPolicyProviderFactory, PasswordPolicyProvider {
public static final int DEFAULT_VALUE = 365; public static final Integer DEFAULT_VALUE = 365;
@Override @Override
public PasswordPolicyProvider create(KeycloakSession session) { public PasswordPolicyProvider create(KeycloakSession session) {
@ -85,7 +85,7 @@ public class ForceExpiredPasswordPolicyProviderFactory implements PasswordPolicy
@Override @Override
public Object parseConfig(String value) { public Object parseConfig(String value) {
return value != null ? Integer.parseInt(value) : DEFAULT_VALUE; return value != null ? Integer.valueOf(value) : DEFAULT_VALUE;
} }
} }

View file

@ -91,17 +91,17 @@ public class ComponentModel implements Serializable {
public int get(String key, int defaultValue) { public int get(String key, int defaultValue) {
String s = get(key); 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) { public long get(String key, long defaultValue) {
String s = get(key); 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) { public boolean get(String key, boolean defaultValue) {
String s = get(key); 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) { public void put(String key, String value) {

View file

@ -143,15 +143,15 @@ public interface RealmModel extends RoleContainerModel {
String getAttribute(String name); String getAttribute(String name);
default Integer getAttribute(String name, Integer defaultValue) { default Integer getAttribute(String name, Integer defaultValue) {
String v = getAttribute(name); 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) { default Long getAttribute(String name, Long defaultValue) {
String v = getAttribute(name); 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) { default Boolean getAttribute(String name, Boolean defaultValue) {
String v = getAttribute(name); String v = getAttribute(name);
return v != null ? Boolean.parseBoolean(v) : defaultValue; return v != null ? Boolean.valueOf(v) : defaultValue;
} }
Map<String, String> getAttributes(); Map<String, String> getAttributes();

View file

@ -35,7 +35,7 @@ public interface PasswordPolicyProvider extends Provider {
default Integer parseInteger(String value, Integer defaultValue) { default Integer parseInteger(String value, Integer defaultValue) {
try { try {
return value != null ? Integer.parseInt(value) : defaultValue; return value != null ? Integer.valueOf(value) : defaultValue;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new PasswordPolicyConfigException("Not a valid number"); throw new PasswordPolicyConfigException("Not a valid number");
} }

View file

@ -46,7 +46,7 @@ class AuthzEndpointQueryStringParser extends AuthzEndpointRequestParser {
protected Integer getIntParameter(String paramName) { protected Integer getIntParameter(String paramName) {
checkDuplicated(requestParams, paramName); checkDuplicated(requestParams, paramName);
String paramVal = requestParams.getFirst(paramName); String paramVal = requestParams.getFirst(paramName);
return paramVal==null ? null : Integer.parseInt(paramVal); return paramVal==null ? null : Integer.valueOf(paramVal);
} }
public String getInvalidRequestMessage() { public String getInvalidRequestMessage() {

View file

@ -81,7 +81,7 @@ public class AuthzEndpointRequestObjectParser extends AuthzEndpointRequestParser
@Override @Override
protected Integer getIntParameter(String paramName) { protected Integer getIntParameter(String paramName) {
Object val = this.requestParams.get(paramName); Object val = this.requestParams.get(paramName);
return val==null ? null : Integer.parseInt(getParameter(paramName)); return val==null ? null : Integer.valueOf(getParameter(paramName));
} }
@Override @Override

View file

@ -46,7 +46,7 @@ class BackchannelAuthenticationEndpointRequestBodyParser extends BackchannelAuth
protected Integer getIntParameter(String paramName) { protected Integer getIntParameter(String paramName) {
checkDuplicated(requestParams, paramName); checkDuplicated(requestParams, paramName);
String paramVal = requestParams.getFirst(paramName); String paramVal = requestParams.getFirst(paramName);
return paramVal==null ? null : Integer.parseInt(paramVal); return paramVal==null ? null : Integer.valueOf(paramVal);
} }
public String getInvalidRequestMessage() { public String getInvalidRequestMessage() {

View file

@ -95,7 +95,7 @@ class BackchannelAuthenticationEndpointSignedRequestParser extends BackchannelAu
@Override @Override
protected Integer getIntParameter(String paramName) { protected Integer getIntParameter(String paramName) {
Object val = this.requestParams.get(paramName); Object val = this.requestParams.get(paramName);
return val==null ? null : Integer.parseInt(getParameter(paramName)); return val==null ? null : Integer.valueOf(getParameter(paramName));
} }
@Override @Override

View file

@ -95,7 +95,7 @@ public class AuthzEndpointParParser extends AuthzEndpointRequestParser {
@Override @Override
protected Integer getIntParameter(String paramName) { protected Integer getIntParameter(String paramName) {
String paramVal = requestParams.get(paramName); String paramVal = requestParams.get(paramName);
return paramVal == null ? null : Integer.parseInt(paramVal); return paramVal == null ? null : Integer.valueOf(paramVal);
} }
public String getInvalidRequestMessage() { public String getInvalidRequestMessage() {

View file

@ -129,7 +129,7 @@ public class JsonConfigProvider implements Config.ConfigProvider {
} }
if (n.isTextual()) { if (n.isTextual()) {
String v = replaceProperties(n.textValue()); String v = replaceProperties(n.textValue());
return !v.isEmpty() ? Integer.parseInt(v) : defaultValue; return !v.isEmpty() ? Integer.valueOf(v) : defaultValue;
} else { } else {
return n.intValue(); return n.intValue();
} }
@ -151,7 +151,7 @@ public class JsonConfigProvider implements Config.ConfigProvider {
} }
if (n.isTextual()) { if (n.isTextual()) {
String v = replaceProperties(n.textValue()); String v = replaceProperties(n.textValue());
return !v.isEmpty() ? Long.parseLong(v) : defaultValue; return !v.isEmpty() ? Long.valueOf(v) : defaultValue;
} else { } else {
return n.longValue(); return n.longValue();
} }
@ -173,7 +173,7 @@ public class JsonConfigProvider implements Config.ConfigProvider {
} }
if (n.isTextual()) { if (n.isTextual()) {
String v = replaceProperties(n.textValue()); String v = replaceProperties(n.textValue());
return !v.isEmpty() ? Boolean.parseBoolean(v) : defaultValue; return !v.isEmpty() ? Boolean.valueOf(v) : defaultValue;
} else { } else {
return n.booleanValue(); return n.booleanValue();
} }