Repository navigation
31.0
Maven
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0-jre</version>
<!-- or, for Android: -->
<version>31.0-android</version>
</dependency>Jar files
Guava requires one runtime dependency, which you can download here:
Javadoc
JDiff
Changelog
Known issue (fixed in patch release 31.0.1): guava-gwt breaks GWT compilation
Other Guava artifacts aren't affected, only users of GWT. (If you are using GWT, you would know it.)
Sorry for missing this during release: It was a known issue, and we had a partial workaround in place, but I forgot to include the problem in the list of release blockers.
To pick up the fix, upgrade to 31.0.1.
Main changes
- Changed
guava-androidto generate Java 8 bytecode. We still restrict ourselves to using APIs available on Ice Cream Sandwich. So, as long as you have enabled Java 8 language features for your Android build, this change should have no effect on Android projects. This change does drop support for Java 7 JREs, as announced last year. - Annotated Guava much more thoroughly for nullness. For details, see the bottom of the release notes.
base: ChangedFunctions.forSupplierandPredicates.instanceOfto accept an additional type argument to specify the input type for the returnedFunction/Predicate. The flexibility we're adding should typically not be necessary if users follow the PECS principle, but it can be useful in some cases, particularly around nullness analysis. Note that this change may require updates to callers' source code (to specify an additional type argument). Still, it maintains binary compatibility. (75110e9)collect: AddedImmutableMap.ofEntries, likeMap.ofEntriesbut forImmutableMap. (cd3b419)collect: Added overloads ofImmutableMap.of,ImmutableBiMap.of, andImmutableSortedMap.offor up to 10 entries. (d5c30e3)collect: RenamedImmutableMap.Builder.build()tobuildOrThrow(). The existingbuild()method will continue to exist but may be deprecated, and the new name should be used in new code. (4bbe12c)collect: Removed@BetafromInternerandInterners. (cf31f3a)collect: Added@InlineMetoStreams.stream(Optional)and friends. (a176cd6)graph: MadeEndpointPair.adjacentNoderequire anNinstead of accept anyObject. (b0be21d)hash: Removed@BetafromHashFunction. (e1cc195)hash: Deprecated buggymurmur3_32, and introducedmurmur3_32_fixed. (a36f08f)io: ChangedCharStreams.asWriter(appendable).write(string[, ...])to reject a nullstring. (50e7ddd)io: Fixed a bug inFileBackedOutputStreamcleanup: If writing to the temp file fails, we now delete it before propagating the exception. (6e054ce)net: ChangedHostAndPort.fromStringto reject port numbers spelled with non-ASCII digits. (53fd1d7)net: AddedHttpHeadersconstants forX-Device-Ip,X-Device-Referer,X-Device-Accept-Language,X-Device-Requested-With,Sec-CH-Prefers-Color-Scheme,Sec-CH-UA-Bitness, andKeep-Alive. (da375be, b23b277, 281edd4, 9c88f9a)primitives: Fixed a rounding bug inUnsignedLong.doubleValue(). (e61cf2e)reflect: Changed the type hierarchy ofInvokable:Invokableno longer inherits fromAccessibleObjectorGenericDeclaration, though it continues to define instance methods with the same signatures as the formerly inherited ones. This is technically a breaking API change to this@BetaAPI. We think it very unlikely that anyone is affected in practice. (12af215)testlib: EnhancedNullPointerTesterto allow a parameter of type<T extends @Nullable Object>to benull. (e856722)testlib: Fixed bug affecting derived tests of custom collection test suites: ThesetUpandtearDownmethods are now copied to derived test suites. (c7d9fef)util.concurrent: AddedServiceManager.startupDurations(). (c95ba5a)util.concurrent: Removed the GWT-only overloads ofFutures.catchingandcatchingAsyncthat let callers omit theExecutor. This matches a change made years ago to the non-GWT API. If this breaks your GWT client code compilation, you can fix it by passing an additional parameter,MoreExecutors.directExecutor()(0ff2f78)
Nullness annotations
Previously, we annotated all parameters that could be null, and we did not annotate elsewhere reliably. Now:
- We consistently annotate return types for nullness.
- We annotate "components" of types, like the element type of an array or list and the bound of a type parameter. (To take advantage, Kotlin users can set
-Xtype-enhancement-improvements-strict-mode.)- However, we don't yet annotate any such locations as non-nullable.
- In our annotations (including on parameters), we distinguish between
@Nullable T("always nullable, regardless of the type argument used forT") andT("nullable only if the type argument is"). - We have temporarily increased our usage of jsr305, which we will ultimately phase out.
- We use
@CheckForNullinstead of a type-annotation@Nullablewherever possible. This makes the nullness information available to more Kotlin users. - We've introduced a custom jsr305 annotation that informs Kotlin that unannotated return types are non-null (just like our usage of
@ParametersAreNonnullByDefaultalready did for parameter types). (To take advantage, Kotlin users can set-Xjsr305=strict.)
- We use
(Known issue: We are missing annotations on the TypeToInstanceMap classes. We'll fix this in a future release.)
By providing additional nullness information, this release may result in more errors or warnings from any nullness analyzers you might use. If so, you may need to fix or suppress them as usual. For advice, see the documentation for the analyzer you're using, such as that for the Checker Framework or for Kotlin.
If you use NullAway with the AnnotatedPackages flag set to cover com.google.common, you may see not only additional legitimate errors but also some incorrect errors because Guava no longer uses @Nullable as frequently on type-variable usages. The NullAway developers have suggested a workaround, and they are planning for NullAway 0.9.9 to treat our type-variable usages differently. However, even after 0.9.9, NullAway users are likely to see some incorrect errors if they keep com.google.common in their AnnotatedPackages. A fuller solution will require Guava and tools to adopt an annotation model that is more suited to generics. For updates on that, follow #2960.
We will be using more annotations to provide more nullness information in the future.