Skip to content

Comments

Get rid of Guava#555

Merged
modmuss50 merged 6 commits intoFabricMC:masterfrom
JFronny:no-guava
Aug 21, 2025
Merged

Get rid of Guava#555
modmuss50 merged 6 commits intoFabricMC:masterfrom
JFronny:no-guava

Conversation

@JFronny
Copy link
Contributor

@JFronny JFronny commented Aug 21, 2025

As suggested on Discord, this PR gets rid of the dependency on Guava.
Mostly, this meant switching code to using Jetbrains annotations for nullability, using the constructors for various collections directly, and replacing Preconditions.checkNotNull with Objects.requireNonNull.
Some things required special changes that may be a bit more controversial:

  • the single usage of Cache in CachingClassProvider was replaced with an ad-hoc cache implementation
  • Multimap usages were replaced with Map<K, Collection<V>> and computeIfAbsent
  • The single usage of Streams.zip was replaced with a custom Iterator implementation
  • I18n was modified to use an index generated by Gradle instead of doing its own reflection
  • EntryTree was modified to extend Collection instead of just Iterable to allow using cleaner construction of copies (Collections constructors do not accept simple iterables)

These changes do have potential to break stuff, so I have quickly checked that things seem to work. If someone that has more experience with this codebase could take a look at them, that would be appreciated.

Copy link
Contributor

@Earthcomputer Earthcomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Make sure you run checkstyle, there are some places where if statements don't have braces.

Edit: not sure how checkstyle passed, but anyway if (condition) throw new IllegalArgumentException(); should have braces.

cache.values().removeIf(value -> value.addTime + expireAfter < time);
}

if (cache.size() > maxSize) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should also be moved to something more careful like the synchronized block above, otherwise multiple threads could pass this check and remove too many entries from the cache. Although I'm questioning whether we even need to remove from the cache if it gets to big, maybe we should only rely on the expire time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was of the opinion that removing one more element in case of a race probably isn't that bad and is probably better than the overhead of an additional synchronization. With that said, I have now added synchronization. One minute is quite a long time, so I'm not sure if removing the check is a good idea.

return entry.classNode;
}

private static final class CacheEntry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this class can be a record

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it can't, as addTime needs to be updated if the cache value is accessed and that isn't possible with records (I could use an Atomic though)

@JFronny
Copy link
Contributor Author

JFronny commented Aug 21, 2025

not sure how checkstyle passed, but anyway

the specific case of checking an argument in an if and throwing an IllegalArgumentException already exists without braces in Command since 2023, so if that failed checkstyle, the current master would probably fail

@Juuxel
Copy link
Member

Juuxel commented Aug 21, 2025

The checkstyle config allows single-line ifs without braces.

Enigma/checkstyle.xml

Lines 82 to 86 in 9abdbd5

<!-- single line statements on one line, -->
<module name="NeedBraces">
<property name="tokens" value="LITERAL_IF,LITERAL_FOR,LITERAL_WHILE"/>
<property name="allowSingleLineStatement" value="true"/>
</module>

@Earthcomputer
Copy link
Contributor

I personally think that should be changed in the checkstyle in a future PR, at least I don't think we should be adding new code with single line if statements.

@modmuss50
Copy link
Member

I personally think that should be changed in the checkstyle in a future PR, at least I don't think we should be adding new code with single line if statements.

I agree, I wasnt even aware that was allowed, I thought it might have just been an enigma thing, but no its also in FAPI.

Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, many thanks.

@modmuss50 modmuss50 merged commit 6d43730 into FabricMC:master Aug 21, 2025
2 checks passed
@JFronny JFronny deleted the no-guava branch August 21, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants