Core Java

The Main Differences Between Java (Latest) and Before

Good morning, and welcome to my talk about the new features in the latest version of Java/<insert your language here>.

You’re going to notice many new things:

  • We now support something unimportant in strings, like emojis
  • We’ve rewritten an API you don’t use
  • We’ve added some optional language features you may one day find useful
  • We’ve deprecated something you were kind of dependent on
  • We’ve introduced some subtle bugs that you may struggle to notice… at first…
  • None of your build tools are going to support this properly for a while

I hope you enjoyed my talk. Have a nice day.

What do you mean “Get out of the TED studios”?

Recent Java 17 Fun

Java 17 is the latest LTS version of Java, and it’s probably a good idea to adopt it. However, some recent pains:

  • Though Amazon has released Corretto 17, they don’t actually support Java 17 in:
    • AWS Lambda Runtimes
    • CodeBuild Runtimes
  • We can work around this by NOT using language level 17 on Lambdas, and by using a docker image to build in CodeBuild… which adds more pain when you’re using docker in docker for testing:
docker run -v ~/.docker:/root/.docker -v /var/run/docker.sock:/var/run/docker.sock -e CODEARTIFACT_AUTH_TOKEN=${CODEARTIFACT_AUTH_TOKEN} -e SNYK_TOKEN=${SNYK_TOKEN} -e SONAR_TOKEN=${SONAR_TOKEN} -v $(pwd):/project -w=/project amazoncorretto:17 ./gradlew clean build snyk-test sonarqube -Dsonar.branch.name="${CURRENT_BRANCH}" -i
  • You have to update Gradle, SpotBugs and Jacoco to latest to get things to work
  • Once you’ve installed JDK 17 on your machine, you’re kind of committed to getting every build to be compatible with the runtime, otherwise you have to jump through hoops to do builds
  • Without the latest SystemStubs, the environment variables hacks in tests are no longer possible
  • There’s a date bug!

Java 17 Date Bug

We use a date parser in one of our projects. As luck would have it, one of our unit tests tried to parse the date 16-Sep-2020 and started to fail on JDK 17.

We could so easily have been testing with 16-Nov-2020 and not noticed the fact that in en-GB locales, Java 17 no longer supports Sep as an abbreviation for the date format MMM. This means that DateFormatter‘s parse method is effectively broken.

Aaaaagh!

Someone on StackOverflow explained this well enough that I could fathom a fix, which is to specialise the date formatter to Locale.ENGLISH which avoid the problem. However, it makes no sense to me at all that a MMM three character month abbreviation should randomly switch from 3 to 4 characters for a single month.

One argument is that Sept is a better abbreviation for the month in natural English. Another argument is that the first argument is talking out of its a-hole.

Conclusion

Be ready for the future, but it’s going to hurt a little bit.

Published on Java Code Geeks with permission by Ashley Frieze, partner at our JCG program. See the original article here: The Main Differences Between Java (Latest) and Before

Opinions expressed by Java Code Geeks contributors are their own.

Ashley Frieze

Software developer, stand-up comedian, musician, writer, jolly big cheer-monkey, skeptical thinker, Doctor Who fan, lover of fine sounds
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button