Skip to content

Commit 88b36ed

Browse files
authored
Merge pull request #1957 from redcape/env_config-npe-fix
Fix NPE when reading null values from env_config
2 parents 2067468 + 339c7d1 commit 88b36ed

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/main/java/com/zendesk/maxwell/Maxwell.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,14 @@ public void run() {
343343
} catch ( URISyntaxException e ) {
344344
// catch URISyntaxException explicitly as well to provide more information to the user
345345
LOGGER.error("Syntax issue with URI, check for misconfigured host, port, database, or JDBC options (see RFC 2396)");
346-
LOGGER.error("URISyntaxException: " + e.getLocalizedMessage());
346+
LOGGER.error("URISyntaxException: " + e.getLocalizedMessage(), e);
347347
System.exit(1);
348348
} catch ( ServerException e ) {
349-
LOGGER.error("Maxwell couldn't find the requested binlog, exiting...");
349+
LOGGER.error("Maxwell couldn't find the requested binlog, exiting...", e);
350350
System.exit(2);
351351
} catch ( Exception e ) {
352352
e.printStackTrace();
353+
LOGGER.error("Maxwell saw an exception and is exiting...", e);
353354
System.exit(1);
354355
}
355356
}

src/main/java/com/zendesk/maxwell/util/AbstractConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ protected Properties readPropertiesEnv(String envConfig) {
114114
Properties properties = new Properties();
115115
for (Map.Entry<String, Object> entry : stringMap.entrySet()) {
116116
LOGGER.debug("Got env_config key: {}", entry.getKey());
117-
properties.put(entry.getKey(), entry.getValue().toString());
117+
if (entry.getKey() != null && entry.getValue() != null) {
118+
properties.put(entry.getKey(), entry.getValue().toString());
119+
}
118120
}
119121
return properties;
120122
} catch (JsonProcessingException e) {

src/test/java/com/zendesk/maxwell/MaxwellConfigTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.contrib.java.lang.system.EnvironmentVariables;
1313

1414
import java.nio.file.Paths;
15+
import java.util.HashMap;
1516
import java.util.Map;
1617

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

8990
@Test
9091
public void testEnvJsonConfig() throws JsonProcessingException {
91-
Map<String, String> configMap = ImmutableMap.<String, String>builder()
92+
Map<String, String> nonNullconfigMap = ImmutableMap.<String, String>builder()
9293
.put("user", "foo")
9394
.put("password", "bar")
9495
.put("host", "remotehost")
9596
.put("kafka.retries", "100")
9697
.build();
98+
HashMap<String, String> configMap = new HashMap<>(nonNullconfigMap);
99+
configMap.put("ignore.me", null);
97100
ObjectMapper mapper = new ObjectMapper();
98101
String jsonConfig = mapper.writeValueAsString(configMap);
99102
environmentVariables.set("MAXWELL_JSON", " " + jsonConfig);

0 commit comments

Comments
 (0)