Live data from Hacker News

JEP 539: Strict Field Initialization in the JVM moved to preview

openjdk.org

1–10 of 21 posts

Re: JEP 539: Strict Field Initialization in the JVM moved to preview

#2
This is a great change that will undoubtedly cause a lot of headaches.

There's a number of libraries (particularly around serialization/marshaling) which will end up mutating `final` fields. In fact, this is a trick I've pulled once or twice in my own code for "reasons" (generally needing to modify behavior of a library because it was deficient).

I suspect this will be one of those things that ends up requiring java devs everywhere to bump up the versions of the libraries they use.

Re: JEP 539: Strict Field Initialization in the JVM moved to preview

#3
post #2

This is a great change that will undoubtedly cause a lot of headaches. There's a number of libraries (particularly around serialization/marshaling) which will end up mutating `final` fields. In fact, this is a trick I've pulled once or twice in my own code for "reasons" (generally needing to modify behavior of a library because it was deficient). I suspect this will be one of those things that ends up requiring java…

Strict Field Initialization is opt-in. A flag needs to be set in the classfile in order to enable it. So should not effect any existing code.

Re: JEP 539: Strict Field Initialization in the JVM moved to preview

#4
post #3
post #2

This is a great change that will undoubtedly cause a lot of headaches. There's a number of libraries (particularly around serialization/marshaling) which will end up mutating `final` fields. In fact, this is a trick I've pulled once or twice in my own code for "reasons" (generally needing to modify behavior of a library because it was deficient). I suspect this will be one of those things that ends up requiring java…

Strict Field Initialization is opt-in. A flag needs to be set in the classfile in order to enable it. So should not effect any existing code.

It won't bite initially, it will bite when you go to update your version of javac in the future and this becomes the default. Or when you update a library that just so happened to be compiled with a newer version of javac.

This particularly matters when you have something likes this

    class Local {
       private final ThirdPartyObject tpo;
    }
or even something like this

    class Local {
      private final LocalDate ld;
    }

Re: JEP 539: Strict Field Initialization in the JVM moved to preview

#8
post #4
post #3

Earlier quoted context omitted.

Strict Field Initialization is opt-in. A flag needs to be set in the classfile in order to enable it. So should not effect any existing code.

It won't bite initially, it will bite when you go to update your version of javac in the future and this becomes the default. Or when you update a library that just so happened to be compiled with a newer version of javac. This particularly matters when you have something likes this class Local { private final ThirdPartyObject tpo; } or even something like this class Local { private final LocalDate ld; }

Extremely easy to fix. Turn it into a record. I’m also pretty sure that cracking final fields is already disabled by default.

Re: JEP 539: Strict Field Initialization in the JVM moved to preview

#10
post #2

This is a great change that will undoubtedly cause a lot of headaches. There's a number of libraries (particularly around serialization/marshaling) which will end up mutating `final` fields. In fact, this is a trick I've pulled once or twice in my own code for "reasons" (generally needing to modify behavior of a library because it was deficient). I suspect this will be one of those things that ends up requiring java…

That's a separate series of JEPs known as "final means final", also starting to land nowadays.

https://openjdk.org/jeps/500

Post reply on HN