Skip to content

Commit af47951

Browse files
committed
Fix potential NPEs
Signed-off-by: Kai Hudalla <[email protected]>
1 parent c9179b8 commit af47951

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

clients/amqp-connection/src/main/java/org/eclipse/hono/client/amqp/tracing/MessageAnnotationsInjectAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public void put(final String key, final String value) {
5858
@SuppressWarnings("unchecked")
5959
private Map<Symbol, String> getPropertiesMap() {
6060
final MessageAnnotations messageAnnotations;
61-
if (message.getMessageAnnotations() == null || message.getMessageAnnotations().getValue() == null) {
61+
if (message.getMessageAnnotations() != null && message.getMessageAnnotations().getValue() != null) {
62+
messageAnnotations = message.getMessageAnnotations();
63+
} else {
6264
messageAnnotations = new MessageAnnotations(new HashMap<>());
6365
message.setMessageAnnotations(messageAnnotations);
64-
} else {
65-
messageAnnotations = message.getMessageAnnotations();
6666
}
6767
final Map<Symbol, String> propertiesMap;
6868
final Object annotationValue = messageAnnotations.getValue().get(Symbol.getSymbol(propertiesMapName));

clients/client-common/src/main/java/org/eclipse/hono/client/util/DownstreamMessageProperties.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.
@@ -48,7 +48,7 @@ public final class DownstreamMessageProperties {
4848

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

51-
private final Map<String, Object> props;
51+
private final Map<String, Object> props = new HashMap<>();
5252
private final ResourceLimits resourceLimits;
5353
private final String endpointName;
5454

@@ -78,7 +78,6 @@ public DownstreamMessageProperties(
7878

7979
this.endpointName = Objects.requireNonNull(endpointName);
8080
this.resourceLimits = resourceLimits;
81-
this.props = new HashMap<>();
8281

8382
Optional.ofNullable(tenantLevelDefaults).ifPresent(props::putAll);
8483
Optional.ofNullable(deviceLevelDefaults).ifPresent(props::putAll);

core/src/main/java/org/eclipse/hono/config/AbstractConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ private KeyCertOptions createKeyCertOptions() {
417417

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

420+
if (format == null) {
421+
LOG.warn("Unable to detect keystore file format for: {}", keyStorePath);
422+
return null;
423+
}
424+
420425
// construct result
421426

422427
switch (format) {

core/src/main/java/org/eclipse/hono/util/CredentialsObject.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,17 @@ public void checkSecrets(final BiConsumer<String, JsonObject> secretValidator) {
287287

288288
} else {
289289

290+
final var credentialsType = getType();
291+
if (credentialsType == null) {
292+
throw new IllegalStateException("credentials object must have a type");
293+
}
294+
290295
try {
291-
switch (getType()) {
296+
switch (credentialsType) {
292297
case CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD:
293298
checkSecrets(secrets, secret -> {
294299
checkHashedPassword(secret);
295-
secretValidator.accept(getType(), secret);
300+
secretValidator.accept(credentialsType, secret);
296301
});
297302
break;
298303
default:

services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/store/Statement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
33
*
44
* See the NOTICE file(s) distributed with this work for additional
55
* information regarding copyright ownership.
@@ -173,7 +173,7 @@ public String toString() {
173173
* @param sql The SQL statement to process. This is a formatted string according to
174174
* {@link String#format(String, Object...)}.
175175
* @param values The values to replace in the parameter {@code sql}.
176-
* @return The statement, or {@code null} if the provided SQL as {@code null}.
176+
* @return The statement, or {@code null} if the provided SQL is {@code null}.
177177
*/
178178
public static Statement statement(final String sql, final Object... values) {
179179
if (sql == null) {

services/device-registry-jdbc/src/main/java/org/eclipse/hono/deviceregistry/jdbc/impl/ClasspathSchemaCreator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ private Future<Void> runScript(final JdbcProperties jdbcProperties, final String
107107
SQL.runTransactionally(jdbcClient, tracer, ctx,
108108
(connection, context) -> {
109109
final var expanded = Statement.statement(script).expand();
110-
log.debug("Creating database schema in [{}] with script: {}", jdbcProperties.getUrl(), expanded);
111-
return expanded
112-
.query(jdbcClient)
113-
.recover(SQL::translateException);
110+
if (expanded == null) {
111+
log.warn("cannot create database schema in [{}]: script can not be expanded to SQL statement",
112+
jdbcProperties.getUrl());
113+
return Future.failedFuture("cannot create database schema using script");
114+
} else {
115+
log.debug("creating database schema in [{}] using script: {}", jdbcProperties.getUrl(), expanded);
116+
return expanded
117+
.query(jdbcClient)
118+
.recover(SQL::translateException);
119+
}
114120
})
115121
.onComplete(ar -> jdbcClient.close(clientCloseTracker));
116122
return clientCloseTracker.future();

0 commit comments

Comments
 (0)