Skip to content

Commit

Permalink
Fix potential NPEs
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Hudalla <[email protected]>
  • Loading branch information
sophokles73 committed Aug 30, 2022
1 parent c9179b8 commit af47951
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void put(final String key, final String value) {
@SuppressWarnings("unchecked")
private Map<Symbol, String> getPropertiesMap() {
final MessageAnnotations messageAnnotations;
if (message.getMessageAnnotations() == null || message.getMessageAnnotations().getValue() == null) {
if (message.getMessageAnnotations() != null && message.getMessageAnnotations().getValue() != null) {
messageAnnotations = message.getMessageAnnotations();
} else {
messageAnnotations = new MessageAnnotations(new HashMap<>());
message.setMessageAnnotations(messageAnnotations);
} else {
messageAnnotations = message.getMessageAnnotations();
}
final Map<Symbol, String> propertiesMap;
final Object annotationValue = messageAnnotations.getValue().get(Symbol.getSymbol(propertiesMapName));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -48,7 +48,7 @@ public final class DownstreamMessageProperties {

private static final Logger LOG = LoggerFactory.getLogger(DownstreamMessageProperties.class);

private final Map<String, Object> props;
private final Map<String, Object> props = new HashMap<>();
private final ResourceLimits resourceLimits;
private final String endpointName;

Expand Down Expand Up @@ -78,7 +78,6 @@ public DownstreamMessageProperties(

this.endpointName = Objects.requireNonNull(endpointName);
this.resourceLimits = resourceLimits;
this.props = new HashMap<>();

Optional.ofNullable(tenantLevelDefaults).ifPresent(props::putAll);
Optional.ofNullable(deviceLevelDefaults).ifPresent(props::putAll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ private KeyCertOptions createKeyCertOptions() {

final FileFormat format = FileFormat.orDetect(this.keyFormat, this.keyStorePath);

if (format == null) {
LOG.warn("Unable to detect keystore file format for: {}", keyStorePath);
return null;
}

// construct result

switch (format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,17 @@ public void checkSecrets(final BiConsumer<String, JsonObject> secretValidator) {

} else {

final var credentialsType = getType();
if (credentialsType == null) {
throw new IllegalStateException("credentials object must have a type");
}

try {
switch (getType()) {
switch (credentialsType) {
case CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD:
checkSecrets(secrets, secret -> {
checkHashedPassword(secret);
secretValidator.accept(getType(), secret);
secretValidator.accept(credentialsType, secret);
});
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -173,7 +173,7 @@ public String toString() {
* @param sql The SQL statement to process. This is a formatted string according to
* {@link String#format(String, Object...)}.
* @param values The values to replace in the parameter {@code sql}.
* @return The statement, or {@code null} if the provided SQL as {@code null}.
* @return The statement, or {@code null} if the provided SQL is {@code null}.
*/
public static Statement statement(final String sql, final Object... values) {
if (sql == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ private Future<Void> runScript(final JdbcProperties jdbcProperties, final String
SQL.runTransactionally(jdbcClient, tracer, ctx,
(connection, context) -> {
final var expanded = Statement.statement(script).expand();
log.debug("Creating database schema in [{}] with script: {}", jdbcProperties.getUrl(), expanded);
return expanded
.query(jdbcClient)
.recover(SQL::translateException);
if (expanded == null) {
log.warn("cannot create database schema in [{}]: script can not be expanded to SQL statement",
jdbcProperties.getUrl());
return Future.failedFuture("cannot create database schema using script");
} else {
log.debug("creating database schema in [{}] using script: {}", jdbcProperties.getUrl(), expanded);
return expanded
.query(jdbcClient)
.recover(SQL::translateException);
}
})
.onComplete(ar -> jdbcClient.close(clientCloseTracker));
return clientCloseTracker.future();
Expand Down

0 comments on commit af47951

Please sign in to comment.