[ https://issues.apache.org/jira/browse/KAFKA-4883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16432854#comment-16432854 ]
ASF GitHub Bot commented on KAFKA-4883: --------------------------------------- rajinisivaram closed pull request #4849: KAFKA-4883: handle NullPointerException while parsing login modue control flag URL: https://github.com/apache/kafka/pull/4849 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/clients/src/main/java/org/apache/kafka/common/security/JaasConfig.java b/clients/src/main/java/org/apache/kafka/common/security/JaasConfig.java index 24bdac23787..5e837a69c16 100644 --- a/clients/src/main/java/org/apache/kafka/common/security/JaasConfig.java +++ b/clients/src/main/java/org/apache/kafka/common/security/JaasConfig.java @@ -81,6 +81,9 @@ public JaasConfig(String loginContextName, String jaasConfigParams) { } private LoginModuleControlFlag loginModuleControlFlag(String flag) { + if (flag == null) + throw new IllegalArgumentException("Login module control flag is not available in the JAAS config"); + LoginModuleControlFlag controlFlag; switch (flag.toUpperCase(Locale.ROOT)) { case "REQUIRED": diff --git a/clients/src/test/java/org/apache/kafka/common/security/JaasContextTest.java b/clients/src/test/java/org/apache/kafka/common/security/JaasContextTest.java index e8535d2c02c..d96b359c1d3 100644 --- a/clients/src/test/java/org/apache/kafka/common/security/JaasContextTest.java +++ b/clients/src/test/java/org/apache/kafka/common/security/JaasContextTest.java @@ -174,6 +174,11 @@ public void testNumericOptionWithoutQuotes() throws Exception { checkInvalidConfiguration("test.testNumericOptionWithoutQuotes required option1=3;"); } + @Test + public void testInvalidControlFlag() throws Exception { + checkInvalidConfiguration("test.testInvalidControlFlag { option1=3;"); + } + @Test public void testNumericOptionWithQuotes() throws Exception { Map<String, Object> options = new HashMap<>(); ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > invalid client sasl.jaas.config triggers NullPointerException > ------------------------------------------------------------- > > Key: KAFKA-4883 > URL: https://issues.apache.org/jira/browse/KAFKA-4883 > Project: Kafka > Issue Type: Bug > Affects Versions: 0.10.2.0 > Reporter: Xavier Léauté > Priority: Minor > > Using an invalid sasl.jaas.config property causes a NullPointerException to > be thrown, which makes it difficult to understand the root of the problem. > Example of an invalid config > {code} > sasl.jaas.config=KafkaClient {\n\ > org.apache.kafka.common.security.plain.PlainLoginModule required\n\ > username="xxxxx"\n\ > password="XXXX";\n\ > } > {code} > Resulting stack trace: > {code} > org.apache.kafka.common.KafkaException: Failed to construct kafka producer > at > org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:342) > at > org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:166) > [...] > Caused by: org.apache.kafka.common.KafkaException: > java.lang.NullPointerException > at > org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:94) > at > org.apache.kafka.common.network.ChannelBuilders.create(ChannelBuilders.java:93) > at > org.apache.kafka.common.network.ChannelBuilders.clientChannelBuilder(ChannelBuilders.java:51) > at > org.apache.kafka.clients.ClientUtils.createChannelBuilder(ClientUtils.java:84) > at > org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:305) > ... 41 more > Caused by: java.lang.NullPointerException > at > org.apache.kafka.common.security.JaasConfig.loginModuleControlFlag(JaasConfig.java:87) > at > org.apache.kafka.common.security.JaasConfig.parseAppConfigurationEntry(JaasConfig.java:110) > at > org.apache.kafka.common.security.JaasConfig.<init>(JaasConfig.java:65) > at > org.apache.kafka.common.security.JaasUtils.jaasConfig(JaasUtils.java:59) > at > org.apache.kafka.common.network.SaslChannelBuilder.configure(SaslChannelBuilder.java:85) > ... 45 more > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)