Skip to content

Commit

Permalink
Merge pull request #1957 from redcape/env_config-npe-fix
Browse files Browse the repository at this point in the history
Fix NPE when reading null values from env_config
  • Loading branch information
osheroff authored Dec 14, 2022
2 parents 2067468 + 339c7d1 commit 88b36ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/zendesk/maxwell/Maxwell.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,14 @@ public void run() {
} catch ( URISyntaxException e ) {
// catch URISyntaxException explicitly as well to provide more information to the user
LOGGER.error("Syntax issue with URI, check for misconfigured host, port, database, or JDBC options (see RFC 2396)");
LOGGER.error("URISyntaxException: " + e.getLocalizedMessage());
LOGGER.error("URISyntaxException: " + e.getLocalizedMessage(), e);
System.exit(1);
} catch ( ServerException e ) {
LOGGER.error("Maxwell couldn't find the requested binlog, exiting...");
LOGGER.error("Maxwell couldn't find the requested binlog, exiting...", e);
System.exit(2);
} catch ( Exception e ) {
e.printStackTrace();
LOGGER.error("Maxwell saw an exception and is exiting...", e);
System.exit(1);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/zendesk/maxwell/util/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ protected Properties readPropertiesEnv(String envConfig) {
Properties properties = new Properties();
for (Map.Entry<String, Object> entry : stringMap.entrySet()) {
LOGGER.debug("Got env_config key: {}", entry.getKey());
properties.put(entry.getKey(), entry.getValue().toString());
if (entry.getKey() != null && entry.getValue() != null) {
properties.put(entry.getKey(), entry.getValue().toString());
}
}
return properties;
} catch (JsonProcessingException e) {
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/com/zendesk/maxwell/MaxwellConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.contrib.java.lang.system.EnvironmentVariables;

import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -88,12 +89,14 @@ public void testEnvVarConfigViaConfigFile() {

@Test
public void testEnvJsonConfig() throws JsonProcessingException {
Map<String, String> configMap = ImmutableMap.<String, String>builder()
Map<String, String> nonNullconfigMap = ImmutableMap.<String, String>builder()
.put("user", "foo")
.put("password", "bar")
.put("host", "remotehost")
.put("kafka.retries", "100")
.build();
HashMap<String, String> configMap = new HashMap<>(nonNullconfigMap);
configMap.put("ignore.me", null);
ObjectMapper mapper = new ObjectMapper();
String jsonConfig = mapper.writeValueAsString(configMap);
environmentVariables.set("MAXWELL_JSON", " " + jsonConfig);
Expand Down

0 comments on commit 88b36ed

Please sign in to comment.