r/java • • Jul 31 '26

JEP 401: Value Objects And JEP 539: Strict Field Initialization Merged Into JDK

https://github.com/openjdk/jdk/commit/cc278dbb8a1ca0754d5842708b9029441055d361
182 Upvotes

64 comments sorted by

View all comments

Show parent comment

3

u/cogman10 Jul 31 '26

The JDK was a major motivator for modules, but it's not as if Java modules weren't intended to be used by the public. There was a lot of effort and tools made to take advantage of the module system which ultimately are mostly unused (jlink, for example). The thought was that end users could do things like generate slim JVMs reducing the runtime requirements.

I think it's fair to call modules somewhat failed. Successful for the JDK, but overall didn't deliver on what it promised to the public.

5

u/lood9phee2Ri Aug 01 '26

The thing is there was something of an early community expectation it would be the standardised replacement for de-facto OSGi bundles, that are really a quite different thing again, and not mutually exclusive with jpms modules - now you just have dynamic osgi bundles AND static jpms modules (and of course unadorned oldschool jars of java language packages) if doing a lot of embedded java stuff. Almost all the time, all 3 roughly align and you just declare things 3 times in somewhat different ways. Or 4/5 if there's enterprise .war / .ear concerns involved.

JPMS does what it says, just doesn't do what a lot of people expected.

Truly a mystery how java gets a rep for redundant bureaucracy.

2

u/EvertTigchelaar Aug 01 '26

Modules are great for library developers.
Before modules you didn't have a good way to have classes only accessible to your library classes. You could have a package name like org.mylib.internal and hope that users wouldn't use classes from that package. With modules you just export the packages your want.

2

u/grashalm01 Aug 02 '26

Module's are useless rn for library maintainers. Because even if you ship your library with a module descriptor people will put it on the class path and ignore your module descriptor as if it weren't there. And no don't expect your users to put your library on the module path because application developers couldn't care less about modules. Nobody wins currently, library devs get extra work with zero benefit.

The JDK does not have this problem because they can enforce module behavior for their libraries always.

1

u/ZimmiDeluxe Aug 02 '26

I would expect IDEs to warn against importing non-exported packages of dependencies, even if they are on the class path, but I haven't checked if that actually happens.

2

u/grashalm01 Aug 03 '26

My IDE doesn't do that. And I don't think it would be a strong enough guarantee.

1

u/ZimmiDeluxe Aug 03 '26

Thinking about it, that should be a javac warning, same as detectable split package shenanigans. It's not a very strong guarantee, but currently you only have the "internal" naming convention to communicate intent, a warning would be an improvement. I've imported internal Hibernate utils in the past by accident, it would have come in handy. Nudging the ecosystem toward modules might be a good idea anyway, at least once Maven 4 is released and building them is less of a hassle.

2

u/grashalm01 Aug 03 '26

I think it should be enforced on the JVM side. With an explicit opt out. I made concrete suggestions to the java team without any success.

3

u/srdoe Aug 01 '26

I don't think this view is accurate, at least not anymore.

Several popular open-source projects have started including module descriptors, for example Netty and Jackson.

And jlink can be used to create slim JVMs even if you're using non-modular jars, it's just slightly more work.