Skip to content

Conversation

@denis-zhdanov
Copy link

This PR applies Traute to the project. The result is that Traute generates runtime null-checks based on NonNull annotations defined in source code.

Consider ATEUtils. applyTaskDescription() for example:

Source code

private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
    ...
}

Resulting bytecode looks like if it's compiled from the source below:

private static void applyTaskDescription(@NonNull Activity activity, @Nullable String key, int color) {
    if (activity == null) {
        throw new NullPointerException("Argument 'activity' of type Activity (#0 out of 3, zero-based) is marked by @android.support.annotation.NonNull but got null for it");
    }
    ...
}

Raw bytecode

javap -c -private ./app/build/intermediates/classes/debug/com/naman14/timber/utils/ATEUtils.class
...
  private static void applyTaskDescription(android.app.Activity, java.lang.String, int);
    Code:
       0: aload_0
       1: ifnonnull     14
       4: new           #28                 // class java/lang/NullPointerException
       7: dup
       8: ldc           #29                 // String Argument 'activity' of type Activity (#0 out of 3, zero-based) is marked by @android.support.annotation.NonNull but got null for it
      10: invokespecial #30                 // Method java/lang/NullPointerException."<init>":(Ljava/lang/String;)V
      13: athrow
       ...

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.

1 participant