You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "coheigea (via GitHub)" <gi...@apache.org> on 2026/10/19 08:28:40 UTC

[PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

coheigea opened a new pull request, #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404

   Generated toString() methods printed an object in full every time it was referenced. Using xs:IDREF, an XML message can reference the same objects over and over, so the output doubles with each level: 23 objects produced a 352-million-character string, and a little more runs out of memory. Simply logging such an object could tie up or crash the server. Each object is now printed in full once per toString() call, and later references print as ClassName@hash, the same short form already used for loops. Output is now proportional to the number of objects, and nothing else about it changes.


-- 
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@cxf.apache.org

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


Re: [PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404#discussion_r4313154492


##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -72,6 +88,63 @@ class JAXBToStringStyleImpl extends ToStringStyle {
         }
     }
         
+    private static CallState callState() {

Review Comment:
   ```suggestion
        private static CallState callState() {
           return  STATE.get();
       }
   ```



-- 
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@cxf.apache.org

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


Re: [PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

Posted by "coheigea (via GitHub)" <gi...@apache.org>.
coheigea merged PR #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404


-- 
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@cxf.apache.org

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


Re: [PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

Posted by "coheigea (via GitHub)" <gi...@apache.org>.
coheigea commented on code in PR #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404#discussion_r4314021102


##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -51,6 +52,21 @@ private JAXBToStringStyle() {
 class JAXBToStringStyleImpl extends ToStringStyle {
     private static final long serialVersionUID = -584903238590491314L;
 
+    /*
+     * The state of the toString() call in progress on this thread, removed once it completes or
+     * fails. commons-lang3 only detects cycles (objects on the current path), so an object
+     * referenced from several places, e.g. through xs:IDREF, would otherwise be printed once per
+     * path, which grows exponentially with the depth of such references.
+     */
+    private static final ThreadLocal<CallState> STATE = new ThreadLocal<>();

Review Comment:
   Thanks, applied both, it’s simpler. The state is still removed after every call (including on failure), and the test now checks it’s clear between calls.



-- 
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@cxf.apache.org

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


Re: [PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404#discussion_r4313146413


##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -51,6 +52,21 @@ private JAXBToStringStyle() {
 class JAXBToStringStyleImpl extends ToStringStyle {
     private static final long serialVersionUID = -584903238590491314L;
 
+    /*
+     * The state of the toString() call in progress on this thread, removed once it completes or
+     * fails. commons-lang3 only detects cycles (objects on the current path), so an object
+     * referenced from several places, e.g. through xs:IDREF, would otherwise be printed once per
+     * path, which grows exponentially with the depth of such references.
+     */
+    private static final ThreadLocal<CallState> STATE = new ThreadLocal<>();

Review Comment:
   ```suggestion
       private static final ThreadLocal<CallState> STATE = ThreadLocal.withInitial(CallState::new);
   ```



-- 
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@cxf.apache.org

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


Re: [PR] Print shared objects only once in JAXBToStringStyle [cxf-xjc-utils]

Posted by "reta (via GitHub)" <gi...@apache.org>.
reta commented on code in PR #404:
URL: https://github.com/apache/cxf-xjc-utils/pull/404#discussion_r4313154492


##########
runtime/src/main/java/org/apache/cxf/xjc/runtime/JAXBToStringStyle.java:
##########
@@ -72,6 +88,63 @@ class JAXBToStringStyleImpl extends ToStringStyle {
         }
     }
         
+    private static CallState callState() {

Review Comment:
   ```suggestion
       private static CallState callState() {
           return  STATE.get();
       }
   ```



-- 
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@cxf.apache.org

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