Skip to content

Conversation

@zml2008
Copy link
Collaborator

@zml2008 zml2008 commented May 27, 2021

Broken out of #96

This is the simplest change -- javac generates nullness checks a bit differently starting with a Java 9 target. FF is patched to support both the old .getClass() and new Objects.requireNonNull() variants.

I tossed in some more debug logging since I was looking forward to some of the other decompile errors that were introduced at the same time.

Diffs (via VanillaGradle workspace)

1.16.5: no change
21w19a: https://paste.gg/p/zml/9e50e0aa7d7c4ab78790f7b5d4b575d1

Add more debug logging in prep for further work
+ }
+ // Calling Objects.requireNonNull and discarding the result is a common pattern in normal code, so we have to be a bit more
+ // cautious about stripping calls when a constructor takes parameters of the instance type
+ // ex. given a class X, `Objects.requireNonNull(someInstanceOfX); new X(someInstanceOfX)` should not have the rNN stripped.
Copy link
Member

@LexManos LexManos May 28, 2021

Choose a reason for hiding this comment

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

Tho this is an okay assumption, looking at where the JDK actually emits the null checks
We have the following cases:

Lambdas: Expr::method
Lambdas: LocalClass::new
Inners: new instance.Inner() 2?
Switch on string with zero cases.

The last one is referenced in a few places. It seems to be adding a null check when creating new instances of classes inside other anon classes?

Anyways, for now this would be an acceptable 'get it working' patch. However the filter system should be more robust and address the actual areas in which the compiler outputs null checks.
Note: The old .getClass() check wasn't as restrictive as i'm saying. But this is more for reference and 'doing it right'

@LexManos LexManos merged commit 4f09c6a into MinecraftForge:master May 28, 2021
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.

3 participants