Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call static method from instance variable #7841

Merged
merged 1 commit into from
Feb 15, 2019
Merged

Don't call static method from instance variable #7841

merged 1 commit into from
Feb 15, 2019

Conversation

tvolkert
Copy link
Contributor

No description provided.

@tvolkert tvolkert merged commit 02d7ca3 into flutter:master Feb 15, 2019
@tvolkert tvolkert deleted the lint branch February 15, 2019 21:18
@matthew-carroll
Copy link
Contributor

The purpose of that invocation was to keep access to all native methods consistent rather than have arbitrary distinctions. Unless there is a technical (non-stylistic) reason for this change, I would prefer that it be changed back.

@tvolkert
Copy link
Contributor Author

It was caught by a linter when rolling into Google. The general logic is that it's an error-prone pattern. Consider the following code:

public class Main {
  static class TheClass {
    public static int theMethod() {
      return 1;
    }
  }

  static class TheSubclass extends TheClass {
    public static int theMethod() {
      return 2;
    }
  }

  public static void main(String[] args) {
    TheClass instanceOfTheClass = new TheSubclass();
    System.out.println(instanceOfTheClass.theMethod());
  }
}

TheSubclass appears to "override" theMethod, so we might expect this code to print the number 2.

The code, however, prints the number 1. The runtime type of instanceOfTheClass, TheSubclass, is ignored; only the static type of the reference, as seen by javac, matters.

In fact, the instance that instanceOfTheClass points to is entirely irrelevant. To prove this, set the variable to null and run again. The program will still print 1, not throw a NullPointerException!

Qualifying a static reference in this way creates an unnecessarily confusing situation.

You could argue that FlutterView will never be subclassed, but I'm not sure we know that to be the case...

@matthew-carroll
Copy link
Contributor

I'm not sure that comparison actually maps to the code in question, but I'll come chat in person.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 16, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Feb 16, 2019
flutter/engine@033f207...163a2fd

git log 033f207..163a2fd --no-merges --oneline
163a2fd Revert "Android embedding refactor pr3 add remaining systemchannels (#7738)" (flutter/engine#7849)
0d6ff16 Shut down and restart the Dart VM as needed. (flutter/engine#7832)
256db4b Android embedding refactor pr3 add remaining systemchannels (flutter/engine#7738)
02d7ca3 Don't call static method from instance variable (flutter/engine#7841)
10cee61 Delete GL textures when they are released from the texture registry. (flutter/engine#7836)
69e4606 Fix NullPointerException in SurfaceTextureRegistryEntry (flutter/engine#7837)
9a965bc Fix NullPointerException in ResourceCleaner (flutter/engine#7838)
2acd794 Add fml::FileExists implementation for Windows (flutter/engine#7845)
fa38a98 Update buildroot to 7f64ff4928e to unblock Mac builds. (flutter/engine#7846)
1ba3295 Add support for calling into other plugins from a background context on iOS (flutter/engine#7843)
df2fc97 Roll src/third_party/skia 154acd7a1374..be9aff25bddc (13 commits) (flutter/engine#7842)
0ca1d1f Remove the Dart JIT snapshot data from AOT builds of the embedder library (flutter/engine#7806)
c51ea41 Roll src/third_party/skia 7a74c7cb6da0..154acd7a1374 (1 commits) (flutter/engine#7840)
ecbaea1 Ensure to pass dill file after VM options for gen_snapshot (flutter/engine#7839)
5d3f714 Roll src/third_party/skia b00f7b34751b..7a74c7cb6da0 (1 commits) (flutter/engine#7835)
7337399 Roll src/third_party/skia 9a88bee122f1..b00f7b34751b (24 commits) (flutter/engine#7831)
6f318ef Move up ndk version that is being downloaded(old one no longer available) (flutter/engine#7830)
a8aa1ee Track flow id (flutter/engine#7826)
b1ce6b7 Roll src/third_party/skia a0dcd29f536b..9a88bee122f1 (4 commits) (flutter/engine#7825)
dbc1663 Roll src/third_party/skia 6152470dc69e..a0dcd29f536b (2 commits) (flutter/engine#7824)
9426776 Roll src/third_party/skia 4037f7f5d8b4..6152470dc69e (1 commits) (flutter/engine#7823)
e2394ad Add flow events connecting pointer events to frames (flutter/engine#7807)
0a5a7c5 Roll src/third_party/skia 09c01e9df260..4037f7f5d8b4 (3 commits) (flutter/engine#7821)
b867f48 Roll src/third_party/skia 186669c4128b..09c01e9df260 (5 commits) (flutter/engine#7820)
af39e22 Fix tests that were committed after cirrus ran (flutter/engine#7819)
1f2cbf7 Roll src/third_party/dart 0a7dcf17eb..c92d5ca288 (64 commits)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop
the roller if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants