News for hackers. Stuff that matters.
Re:Which version of JDK should I use? by chrisseaton on Sunday October 10, 2021 @04:24PM (#28821647)
Can you give a specific technical problem with updating from 8 to 11? Everyone says it's hard - nobody's ever able to give a practical example of a problem.
Re:Which version of JDK should I use? by jeroenhd on Sunday October 10, 2021 @06:29PM (#28822563)
Oh, I have a fun one. The company I work at leverages Nashorn for running some user-customizable scripts and when upgrading from 8 to 11 we found out that Nashorn changed the way they express numbers under the hood. Basically, every number is either an integer or a float and it used to be that every number was a long or a float.

This silently broke a bunch of scripts and callbacks because of class cast exceptions and such. The solution was to rewrite the scripts in such a way to import the Java Long class and use that directly to express large integers.

The most important breaking issues I've found were not necessarily in our code base, but in dependencies. Libraries that include libraries that include libraries, all doing their own thing, a lot of the time involving some pretty scary reflection stuff for some unexplained reason. Blindly upgrading libraries only gets you so far, sometimes a dependency gets abandoned and you need to find a replacement and rewrite your code to call the APIs in the right manner to be backwards compatible enough.

Re:Which version of JDK should I use? by chrisseaton on Sunday October 10, 2021 @06:33PM (#28822583)
> involving some pretty scary reflection stuff for some unexplained reason

This is where it always seems to end up. Why do people bend over so far backwards doing reflection that isn't specified?

Re:Which version of JDK should I use? by lmm on Sunday October 10, 2021 @11:02PM (#28824187)
Because Java, particularly pre-8 Java, sucks so bad if you try to actually write your whole application in it.

(I always found this really frustrating when making the argument for Scala. Yes, Scala-the-language is more complex than Java-the-language. But it's not more complex than the pile of reflection magic that anyone who tries to write a nontrivial system in Java actually ends up using).

Re:Which version of JDK should I use? by chrisseaton on Monday October 11, 2021 @05:16AM (#28826356)
I try to do everything in plain-old Java, and my code just keeps running release to release.
Re:Which version of JDK should I use? by jeroenhd on Sunday October 10, 2021 @09:00PM (#28823463)
From what I've seen: to add automagic functionality, syntactic sugar and wrapper methods for libraries. The JVM/Java language doesn't seem to have the tooling necessary to accomplish this natively, so it's the only reliable way to do it without relying on annotation processors having properly run (which still require some reflection magic, depending on the use case).
Re:Which version of JDK should I use? by vips7L on Sunday October 10, 2021 @07:24PM (#28822878)
Reflection and class loader shenanigans to shoot them selves in the foot.
Re:Which version of JDK should I use? by cesarb on Sunday October 10, 2021 @08:19PM (#28823209)
> Why do people bend over so far backwards doing reflection that isn't specified?

Either because there's no other way to do it, or because the official way is too slow.

Re:Which version of JDK should I use? by heelix on Sunday October 10, 2021 @10:54PM (#28824140)
It is the dependencies. We bit the bullet and cut over (most) everything to Java 11 last year. Things that were removed from the JDK into new dependencies were the easier bits to sort - JAXB, some old Sun classes, and Java EE bits. All that was less than a week to sort. The real work were with the older 3rd party libraries not making the jump. You end up with turtles all the way down in some cases. Those took a serious amount of hunting for replacement. Mind you, the code was almost always something that had no budget or appetite for maintenance, so the moment you had to jump to a new package/API... folks often gave up.

All that said - for the 'normal' Springboot applications, we saw almost a 25% performance jump for the same code - updated libraries - running on K8. Java 11 was a substantial performance improvement. The jump for us to Java 17 will happen this winter, and looks to be a non-issue so far.

Re:Which version of JDK should I use? by KronisLV on Sunday October 10, 2021 @04:43PM (#28821806)
I sadly didn't write everything down, or didn't keep references to the GitHub issues, but here's a few of the things that i ran into.

Here's a list of the things that were available in JDK 8 and no longer are: https://advancedweb.hu/a-categorized-list-of-all-java-and-jv...

When you stumble upon something like that, at best you can import a Maven dependency with a version that has what you need, at worst you need to rewrite the code to use another library or set of libraries.

If you have any low level logic like custom class loaders written against older JDK versions (think before 8), then they'll be forwards compatible until 8 for the most part, but will break afterwards. Coincidentally, reading code that deals with low level logic is also not easy to do, especially if it's not commented well.

If you rely upon reflection, or use advanced language features (like the JasperReports framework for generating PDFs, which also has a build step for building the reports), in some cases things might compile but not work at runtime due to class mismatches.

Many frameworks need new major versions to support newer releases than JDK 8, for example Spring Boot 1.5 needs to be upgraded, so you're also dealing with all the changes that are encapsulated by your dependencies. In another project that i also migrated, needed to rewrite a lot of web initialization code for Spring Boot 2.X.

Not only that, but with those framework changes, certain things can break in the actual environments. For example, if you package your app as a far .jar, then you'll no longer be able to serve JSP files out of it. It makes no sense, but packaging it as a .war which can be executed with "java -jar your-app.war" will work for some reason.

I some other libraries, method names remain the same, but signatures change, or sometimes things just get deprecated and removed - you have to deal with all of that, which is especially unfun in code that isn't commented but that the business depends on to work correctly. Throw in external factors such as insufficient coverage of tests and you're in for an interesting time. I'm not saying that it's a type of environment that should be condoned, but it's the objective reality in many software projects.

Oh and i hope that you're also okay with updating all of your app servers (like Tomcat) or JDK installs on the server as well, especially if you depend on some of the Tomcat libraries to be provided and for your frameworks/libraries that depend on them being present at runtime to accept those new versions effortlessly. It all feels very brittle at times.

This is especially a nightmare if your servers were configured manually - personally i'm introducing Ansible and containers to at least isolate the damage of Ops rot, but it's been an uphill battle since day 1.

Here's an exceedingly stupid one: sometimes there are checks in code to make sure that you're using the right version of JDK (or even the Oracle JDK), which get confused with the larger versions. It's easy to fix when it's your code, but really annoying when it's external tools - personal nitpick.

Addendum: here's something that i expected to break, but didn't. We use myBatis as an ORM. It has XML mapper files that define how to map entities and construct queries against the DB based on that. Also, it uses Java interfaces and dynamically calls the underlying XML code as necessary. So essentially you have an interface, which has a corresponding XML file in which you have quasi-Java code (e.g. checking what parameters are passed in to the query) that's used alongside a number of tags to dynamically build SQL queries. Here's an example: https://mybatis.org/mybatis-3/dynamic-sql.html

Instead of something breaking in myBatis, what broke actually was Hibernate in the newer versions of Spring. Oh, and Flyway for DB migrations simply used to work with a particular Oracle DB version as well.