Even better is getting Gradle/Maven to correctly pull "plain" vs "Android" versions of the package instead of them just publishing the diverging code base as two repository packages.
I wish Guava weren’t just one library that breaks backward compatibility casually. They follow semver, but the major version changes so often that it’s not that helpful (they’re up to 32.x!)
Does Java have a solution for such things where both libs can use their own version without them conflicting (unless they hand out Guava types to others, of course)? Custom class loaders?
Java doesn’t have a universal practical solution for this. Principled solutions based on custom class loaders (such as OSGi) added tremendous complexity and created more problems than they solved. Other solutions such as shading (renaming classes and their usages to prevent name conflicts between different versions) work in some cases but have their own limitations and drawbacks.
Yes custom class loaders can solve this. Eclipse had an entire OSGI module system that did this among other things. In general though Java (and Kotlin) have been trending toward simpler and lighter though for years and I’d recommend just sorting out your dependencies, even drop some, to avoid that kind of thing.
“If your uber JAR is likely to be used as a dependency in another application then there's a risk that the versions of the dependent classes in the uber JAR might clash with versions of those same dependencies in this other application. Shading helps to avoid any such issue by renaming the packages within the uber JAR”
> unless they hand out Guava types to others, of course
You still can hand out guava objects to others, as long as you hand them out as being of a standard Java interface.
That will work as long as the receiver of the type uses instanceof with a class type or reflection, so it is a bit brittle. Technically, any breakage would indicate a bug in the receiving code, but fixing it cleanly may be impossible.
I dealt with a repo that admitted only one version of each library, probably following Google's lead, so we were stuck with an old version of Guava because it was used all over the place, and upgrading it would have required a lot of refactoring which was not worth anyone's time. One reason to prefer smaller libraries. https://en.wikipedia.org/wiki/Public_goods_game
CVEs are terrible nowadays. Any enterprising ”security researcher” can file one against your project, and the CVE aggregators will flat refuse to take it down. See for example CVE-2023-29827 or CVE-2023-35116
Does the standard library have a function to parse IP addresses without querying DNS? InetAddresses.forString() was the main reason I used Guava in the past.
Not 100% sure why this is here, considering its age, but it always struck me as strange that they never did anything with Dates. The stdlib offering for Dates in Java/JVM environments is atrocious.
Not sure what you mean. java.util.Date is terrible, but the newer java.util.time.* classes are some of the best I've worked with when it comes to datetimes.
I liked Apache Commons collections for major versioning their releases. Collections 4 is in the collections4 package. Allows having both versions and incrementally migrating. Would have been useful because Guava is like JQuery: it had so much useful stuff, upstream stuff would often include it and then you have to worry about compatibility.
Happy Guava user here. I frequently use the services and eventbus bits. Some of the io, primitives and cache stuff. Table is also useful. Very nice to have this, has definitely made life easier for me.
From the documentation... "We recommend against using EventBus. It was designed many years ago, and newer libraries offer better ways to decouple components and react to events."
This and Apache Commons is the jQuery of Java - once a useful tool to get cutting edge features and entire paradigms into older versions, now a security risk and surprisingly unperformant compared to what the standard library has to offer.
I think we were able to remove 99% of usage of Guava and Apache Commons Lang/Text by porting the remainder of our code over to Kotlin. Kotlin's stdlib has most of what we used from these tool libs built-in. The remaining 1% + removing the deps is on the backlog.
We may at some point go with Kotlin's Arrow lib (an FP specific tool lib), which may be akin to underscore.js in JS.
50 comments
[ 2.5 ms ] story [ 107 ms ] threadhttps://github.com/google/guava/issues/2914
Used it for JavaFX apps with no problems.
Although people often skip it and put everything in one module. It was released in Java 9 (started in 2014 and completed fully in 2017).
https://stackoverflow.com/a/49811665:
“If your uber JAR is likely to be used as a dependency in another application then there's a risk that the versions of the dependent classes in the uber JAR might clash with versions of those same dependencies in this other application. Shading helps to avoid any such issue by renaming the packages within the uber JAR”
> unless they hand out Guava types to others, of course
You still can hand out guava objects to others, as long as you hand them out as being of a standard Java interface.
That will work as long as the receiver of the type uses instanceof with a class type or reflection, so it is a bit brittle. Technically, any breakage would indicate a bug in the receiving code, but fixing it cleanly may be impossible.
Java 9 modules address this.
See grandparent: "dealing with mismatching guava versions brought in as transitive dependencies"
https://github.com/ben-manes/caffeine
(And then it was included in Java 8 in java.time.*)
We may at some point go with Kotlin's Arrow lib (an FP specific tool lib), which may be akin to underscore.js in JS.