Get rid of Guava#555
Conversation
enigma/src/main/java/cuchaz/enigma/bytecode/translators/LocalVariableFixVisitor.java
Outdated
Show resolved
Hide resolved
enigma/src/main/java/cuchaz/enigma/classprovider/CachingClassProvider.java
Outdated
Show resolved
Hide resolved
| cache.values().removeIf(value -> value.addTime + expireAfter < time); | ||
| } | ||
|
|
||
| if (cache.size() > maxSize) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Nit: this class can be a record
There was a problem hiding this comment.
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)
enigma/src/main/java/cuchaz/enigma/translation/mapping/EntryResolver.java
Outdated
Show resolved
Hide resolved
the specific case of checking an argument in an if and throwing an IllegalArgumentException already exists without braces in |
|
The checkstyle config allows single-line ifs without braces. Lines 82 to 86 in 9abdbd5 |
|
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. |
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.checkNotNullwithObjects.requireNonNull.Some things required special changes that may be a bit more controversial:
CacheinCachingClassProviderwas replaced with an ad-hoc cache implementationMultimapusages were replaced withMap<K, Collection<V>>andcomputeIfAbsentStreams.zipwas replaced with a customIteratorimplementationI18nwas modified to use an index generated by Gradle instead of doing its own reflectionEntryTreewas modified to extendCollectioninstead of justIterableto 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.