You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "mrniko (via GitHub)" <gi...@apache.org> on 2026/10/07 10:04:09 UTC

[I] a final field is written but never restored [fory]

mrniko opened a new issue, #4136:
URL: https://github.com/apache/fory/issues/4136

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues.
   
   
   ### Version
   
   1.7.6
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   ```java
   public class FinalFieldLoss {
   
       public static class Holder {
           private final String a;
           public Holder() { a = null; }
           public Holder(String a) { this.a = a; }
           public String toString() { return "Holder(a=" + a + ")"; }
       }
   
       public static void main(String[] args) {
           ForyJson fory = ForyJson.builder().withFieldMode(true).build();
           byte[] json = fory.toJsonBytes(new Holder("v"));
           System.out.println(new String(json));              // {"a":"v"}
           System.out.println(fory.fromJson(json, Holder.class));
       }
   }
   ```
   
   ### What did you expect to see?
   
   `Holder(a=v)`
   
   A document Fory itself just wrote should read back to an equal object. Whether a field is final is a property of the Java class, not of the JSON, so it should not change what the wire format can carry — and fory-core does restore it (below), so this is the behaviour already established in the project. Failing that, an error at write time or at read time saying the field cannot be assigned.
   
   ### What did you see instead?
   
   `Holder(a=null)`
   
   ### Anything Else?
   
   The defect does not depend on field mode, visibility, accessors or codegen:
    
   | variant | result |
   | --- | --- |
   | `private final` field, `withFieldMode(true)` | value lost |
   | `public final` field | value lost |
   | `private final` field with a getter | value lost |
   | `withFieldMode(false)` (bean mode) | value lost |
   | `withCodegen(false)` | value lost |
   | `private` **non-final** field (control) | correct |
   
   ### Are you willing to submit a PR?
   
   - [ ] I'm willing to submit a PR!


-- 
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: commits-unsubscribe@fory.apache.org.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] A final field is written but never restored [fory]

Posted by "mrniko (via GitHub)" <gi...@apache.org>.
mrniko commented on issue #4136:
URL: https://github.com/apache/fory/issues/4136#issuecomment-6056313747

   Thank you!


-- 
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: commits-unsubscribe@fory.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] A final field is written but never restored [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #4136: A final field is written but never restored
URL: https://github.com/apache/fory/issues/4136


-- 
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: commits-unsubscribe@fory.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org