You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/01/19 20:07:15 UTC

[GitHub] [jackrabbit-oak] klcodanr opened a new pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

klcodanr opened a new pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470


   Currently performing the following will result in a NullPointerException as null values for the properties or child objects are not checked:
   
   ```
     JsonObject a = new JsonObject(true);
     a.getChildren().put("test", (JsonObject) null);
   ```
   
   This PR introduces checks to ensure null children and null properties can be set on a JsonObject without the toString method failing.


-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] thomasmueller merged pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
thomasmueller merged pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470


   


-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] reschke commented on a change in pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
reschke commented on a change in pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470#discussion_r788425027



##########
File path: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/json/JsonObject.java
##########
@@ -146,15 +146,19 @@ public String toString() {
     }
 
     private static void toJson(JsopBuilder buf, JsonObject obj) {
-        buf.object();
-        for (String name : obj.props.keySet()) {
-            buf.key(name).encodedValue(obj.props.get(name));
+        if(obj == null){

Review comment:
       ```suggestion
           if (obj == null) {
   ```




-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] reschke commented on a change in pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
reschke commented on a change in pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470#discussion_r788425027



##########
File path: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/json/JsonObject.java
##########
@@ -146,15 +146,19 @@ public String toString() {
     }
 
     private static void toJson(JsopBuilder buf, JsonObject obj) {
-        buf.object();
-        for (String name : obj.props.keySet()) {
-            buf.key(name).encodedValue(obj.props.get(name));
+        if(obj == null){

Review comment:
       ```suggestion
           if (obj == null){
   ```




-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] reschke commented on a change in pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
reschke commented on a change in pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470#discussion_r788423010



##########
File path: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/json/JsonObject.java
##########
@@ -146,15 +146,19 @@ public String toString() {
     }
 
     private static void toJson(JsopBuilder buf, JsonObject obj) {
-        buf.object();
-        for (String name : obj.props.keySet()) {
-            buf.key(name).encodedValue(obj.props.get(name));
+        if(obj == null){

Review comment:
       broken whitespace




-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] klcodanr commented on pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
klcodanr commented on pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470#issuecomment-1023696816


   @reschke  / @thomasmueller  I believe I have addressed the concerns raised, could you please re:review?


-- 
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: dev-unsubscribe@jackrabbit.apache.org

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



[GitHub] [jackrabbit-oak] thomasmueller commented on a change in pull request #470: OAK-9672 - Adding checks to support setting null values in oak-commons JSON

Posted by GitBox <gi...@apache.org>.
thomasmueller commented on a change in pull request #470:
URL: https://github.com/apache/jackrabbit-oak/pull/470#discussion_r788449391



##########
File path: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/json/JsopBuilder.java
##########
@@ -208,12 +210,20 @@ public JsopBuilder value(String value) {
      */
     @Override
     public JsopBuilder encodedValue(String value) {
-        optionalCommaAndNewline(value.length());
+        optionalCommaAndNewline(strLength(value));
         buff.append(value);
         needComma = true;
         return this;
     }
 
+    private int strLength(@Nullable String value) {
+        if (value != null) {
+            return value.length();
+        } else {
+            return 4;// null = 4 chars

Review comment:
       Suggested change:
   
               return "null".length();
   




-- 
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: dev-unsubscribe@jackrabbit.apache.org

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