[jira] [Commented] (KAFKA-5550) Struct.put() should include the field name if validation fails

2018-02-12 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/KAFKA-5550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16361101#comment-16361101
 ] 

ASF GitHub Bot commented on KAFKA-5550:
---

hachikuji closed pull request #3507: KAFKA-5550 
URL: https://github.com/apache/kafka/pull/3507
 
 
   

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/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java 
b/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
index 6e7b5d23bbd..5e4de21b632 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/Struct.java
@@ -211,7 +211,9 @@ public Struct put(String fieldName, Object value) {
  * @return the Struct, to allow chaining of {@link #put(String, Object)} 
calls
  */
 public Struct put(Field field, Object value) {
-ConnectSchema.validateValue(field.schema(), value);
+if (null == field)
+throw new DataException("field cannot be null.");
+ConnectSchema.validateValue(field.name(), field.schema(), value);
 values[field.index()] = value;
 return this;
 }
diff --git 
a/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java 
b/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
index 42345b1986c..e91960576a1 100644
--- a/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
+++ b/connect/api/src/test/java/org/apache/kafka/connect/data/StructTest.java
@@ -266,4 +266,28 @@ public void testValidateFieldWithInvalidValueType() {
 thrown.expectMessage("Invalid Java object for schema type INT8: class 
java.lang.Object for field: \"field\"");
 ConnectSchema.validateValue(fieldName, Schema.INT8_SCHEMA, new 
Object());
 }
+
+@Test
+public void testPutNullField() {
+final String fieldName = "fieldName";
+Schema testSchema = SchemaBuilder.struct()
+.field(fieldName, Schema.STRING_SCHEMA);
+Struct struct = new Struct(testSchema);
+
+thrown.expect(DataException.class);
+Field field = null;
+struct.put(field, "valid");
+}
+
+@Test
+public void testInvalidPutIncludesFieldName() {
+final String fieldName = "fieldName";
+Schema testSchema = SchemaBuilder.struct()
+.field(fieldName, Schema.STRING_SCHEMA);
+Struct struct = new Struct(testSchema);
+
+thrown.expect(DataException.class);
+thrown.expectMessage("Invalid value: null used for required field: 
\"fieldName\", schema type: STRING");
+struct.put(fieldName, null);
+}
 }


 


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


> Struct.put() should include the field name if validation fails
> --
>
> Key: KAFKA-5550
> URL: https://issues.apache.org/jira/browse/KAFKA-5550
> Project: Kafka
>  Issue Type: Bug
>  Components: KafkaConnect
>Reporter: Jeremy Custenborder
>Assignee: Jeremy Custenborder
>Priority: Minor
>
> When calling struct.put() with an invalid value, the error message should 
> include the field name.
> {code:java}
> @Test
> public void testPutIncludesFieldName() {
> final String fieldName = "fieldName";
> Schema testSchema = SchemaBuilder.struct()
> .field(fieldName, Schema.STRING_SCHEMA);
> Struct struct = new Struct(testSchema);
> try {
> struct.put(fieldName, null);
> } catch (DataException ex) {
> assertEquals(
> "Invalid value: null used for required field: \"fieldName\", 
> schema type: STRING",
> ex.getMessage()
> );
> }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (KAFKA-5550) Struct.put() should include the field name if validation fails

2017-07-07 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/KAFKA-5550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16078943#comment-16078943
 ] 

ASF GitHub Bot commented on KAFKA-5550:
---

GitHub user jcustenborder opened a pull request:

https://github.com/apache/kafka/pull/3507

KAFKA-5550 

Changed call to use the overload of ConnectSchema.validate method with the 
field name passed in. Ensure that field in put call is not null.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/jcustenborder/kafka KAFKA-5550

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/kafka/pull/3507.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #3507


commit 91741942912426e33ad032cdddfeecbc66edd37c
Author: Jeremy Custenborder 
Date:   2017-07-01T02:07:10Z

KAFKA-5550 Changed call to use the overload of 
ConnectSchema.validateValue() method with the field name passed in. Ensure that 
field in put call is not null.




> Struct.put() should include the field name if validation fails
> --
>
> Key: KAFKA-5550
> URL: https://issues.apache.org/jira/browse/KAFKA-5550
> Project: Kafka
>  Issue Type: Bug
>  Components: KafkaConnect
>Reporter: Jeremy Custenborder
>Assignee: Jeremy Custenborder
>Priority: Minor
>
> When calling struct.put() with an invalid value, the error message should 
> include the field name.
> {code:java}
> @Test
> public void testPutIncludesFieldName() {
> final String fieldName = "fieldName";
> Schema testSchema = SchemaBuilder.struct()
> .field(fieldName, Schema.STRING_SCHEMA);
> Struct struct = new Struct(testSchema);
> try {
> struct.put(fieldName, null);
> } catch (DataException ex) {
> assertEquals(
> "Invalid value: null used for required field: \"fieldName\", 
> schema type: STRING",
> ex.getMessage()
> );
> }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)