dajac commented on a change in pull request #11695:
URL: https://github.com/apache/kafka/pull/11695#discussion_r796350195



##########
File path: core/src/main/scala/kafka/tools/ConsoleProducer.scala
##########
@@ -362,11 +374,22 @@ object ConsoleProducer {
     }
 
     private def splitHeaders(headers: String): Array[(String, Array[Byte])] = {
-      headerSeparatorPattern.split(headers).map { pair =>
-        (pair.indexOf(headerKeySeparator), ignoreError) match {
+      headersSeparatorPattern.split(headers).map { pair =>
+        (pair.indexOf(headersKeySeparator), ignoreError) match {
           case (-1, false) => throw new KafkaException(s"No header key 
separator found in pair '$pair' on line number $lineNumber")
           case (-1, true) => (pair, null)
-          case (i, _) => (pair.substring(0, i), pair.substring(i + 
headerKeySeparator.length).getBytes(StandardCharsets.UTF_8))
+          case (i, _) =>
+            val headerKey = pair.substring(0, i) match {
+              case k if k == nullMarker =>
+                  throw new KafkaException(s"Header keys should not be equal 
to the null marker '$nullMarker' as they can't be null")

Review comment:
       nit: Indentation seems to be off for this line.

##########
File path: core/src/main/scala/kafka/tools/ConsoleProducer.scala
##########
@@ -302,22 +304,32 @@ object ConsoleProducer {
       if (props.containsKey("key.separator"))
         keySeparator = props.getProperty("key.separator")
       if (props.containsKey("parse.headers"))
-        parseHeader = 
props.getProperty("parse.headers").trim.equalsIgnoreCase("true")
+        parseHeaders = 
props.getProperty("parse.headers").trim.equalsIgnoreCase("true")
       if (props.containsKey("headers.delimiter"))
         headersDelimiter = props.getProperty("headers.delimiter")
       if (props.containsKey("headers.separator"))
         headersSeparator = props.getProperty("headers.separator")
-        headerSeparatorPattern = Pattern.compile(headersSeparator)
+        headersSeparatorPattern = Pattern.compile(headersSeparator)

Review comment:
       nit: Not related to you change. The indentation of this line is weird. 
Should we align it on the `if` instead?

##########
File path: core/src/main/scala/kafka/tools/ConsoleProducer.scala
##########
@@ -362,11 +374,22 @@ object ConsoleProducer {
     }
 
     private def splitHeaders(headers: String): Array[(String, Array[Byte])] = {
-      headerSeparatorPattern.split(headers).map { pair =>
-        (pair.indexOf(headerKeySeparator), ignoreError) match {
+      headersSeparatorPattern.split(headers).map { pair =>
+        (pair.indexOf(headersKeySeparator), ignoreError) match {
           case (-1, false) => throw new KafkaException(s"No header key 
separator found in pair '$pair' on line number $lineNumber")
           case (-1, true) => (pair, null)
-          case (i, _) => (pair.substring(0, i), pair.substring(i + 
headerKeySeparator.length).getBytes(StandardCharsets.UTF_8))
+          case (i, _) =>
+            val headerKey = pair.substring(0, i) match {
+              case k if k == nullMarker =>
+                  throw new KafkaException(s"Header keys should not be equal 
to the null marker '$nullMarker' as they can't be null")
+              case k => k
+            }
+            val headerValue = pair.substring(i + headersKeySeparator.length) 
match {
+              case v if v == nullMarker =>
+                null

Review comment:
       nit: I would put `null` on the previous line to stay in line with the 
second case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to