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

Android Release Build NoSuchMethodError #22131

Closed
IhorKlimov opened this issue Sep 21, 2018 · 10 comments
Closed

Android Release Build NoSuchMethodError #22131

IhorKlimov opened this issue Sep 21, 2018 · 10 comments
Assignees
Labels
c: crash Stack traces logged to the console dependency: dart Dart team may need to help us waiting for PR to land (fixed) A fix is in flight

Comments

@IhorKlimov
Copy link

IhorKlimov commented Sep 21, 2018

Occurs only on release build, right at the app's startup time

screenshot

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, v0.9.2, on Microsoft Windows [Version 10.0.17134.285], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    X Android license status unknown.
[√] Android Studio (version 3.1)
[√] VS Code, 64-bit edition (version 1.24.0)
[√] Connected devices (1 available)

! Doctor found issues in 1 category.

adb logcat

09-22 10:05:59.249 12713 12713 I zygote  : android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
09-22 10:05:59.371 12713 12748 I flutter : ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
09-22 10:05:59.372 12713 12748 I flutter : The following NoSuchMethodError was thrown building Application(dirty):
09-22 10:05:59.372 12713 12748 I flutter : The method '&' was called on null.
09-22 10:05:59.372 12713 12748 I flutter : Receiver: null
09-22 10:05:59.372 12713 12748 I flutter : Tried calling: &()
09-22 10:05:59.373 12713 12748 I flutter : 
09-22 10:05:59.373 12713 12748 I flutter : When the exception was thrown, this was the stack:
09-22 10:05:59.374 12713 12748 I flutter : #0      _HashBase._hashPattern (dart:collection/runtime/libcompact_hash.dart:98)
09-22 10:05:59.374 12713 12748 I flutter : #1      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin._getValueOrData (dart:collection/runtime/libcompact_hash.dart:329)
09-22 10:05:59.374 12713 12748 I flutter : #2      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.[] (dart:collection/runtime/libcompact_hash.dart:351)
09-22 10:05:59.374 12713 12748 I flutter : #3      ColorSwatch.[] (package:flutter/src/painting/colors.dart:550)
09-22 10:05:59.374 12713 12748 I flutter : #4      new ThemeData. (package:flutter/src/material/theme_data.dart:160)
09-22 10:05:59.374 12713 12748 I flutter : #5      Application.build (package:shenanny/main.dart:33)
09-22 10:05:59.374 12713 12748 I flutter : #6      StatelessElement.build (package:flutter/src/widgets/framework.dart:3731)
09-22 10:05:59.374 12713 12748 I flutter : #7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3678)
09-22 10:05:59.374 12713 12748 I flutter : #8      Element.rebuild (package:flutter/src/widgets/framework.dart:3531)
09-22 10:05:59.375 12713 12748 I flutter : #9      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3658)
09-22 10:05:59.375 12713 12748 I flutter : #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3653)
09-22 10:05:59.375 12713 12748 I flutter : #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2937)
09-22 10:05:59.375 12713 12748 I flutter : #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2740)
09-22 10:05:59.375 12713 12748 I flutter : #13     RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:881)
09-22 10:05:59.375 12713 12748 I flutter : #14     RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:852)
09-22 10:05:59.375 12713 12748 I flutter : #15     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:798)
09-22 10:05:59.375 12713 12748 I flutter : #16     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2253)
09-22 10:05:59.375 12713 12748 I flutter : #17     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:797)
09-22 10:05:59.375 12713 12748 I flutter : #18     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:689)
09-22 10:05:59.375 12713 12748 I flutter : #19     runApp (package:flutter/src/widgets/binding.dart:728)
09-22 10:05:59.375 12713 12748 I flutter : #20     main (package:shenanny/main.dart:13)
09-22 10:05:59.375 12713 12748 I flutter : #21     _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289)
09-22 10:05:59.375 12713 12748 I flutter : #22     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171)
09-22 10:05:59.375 12713 12748 I flutter : ════════════════════════════════════════════════════════════════════════════════════════════════════
09-22 10:05:59.447 12713 12730 I FA      : Tag Manager is not found and thus will not be used
09-22 10:05:59.465 12713 12756 D OpenGLRenderer: HWUI GL Pipeline
09-22 10:05:59.524 12713 12756 I OpenGLRenderer: Initialized EGL, version 1.4
09-22 10:05:59.524 12713 12756 D OpenGLRenderer: Swap behavior 2
09-22 10:05:59.591   367   367 W /system/bin/hwservicemanager: getTransport: Cannot find entry android.hardware.graphics.mapper@2.0::IMapper/default in either framework or device manifest.

P.S. Works fine on v0.9.1

@mraleph
Copy link
Member

mraleph commented Sep 22, 2018

Do you have any detailed stack trace (e.g. try looking into adb logcat)?

@IhorKlimov
Copy link
Author

@mraleph Added

@mraleph
Copy link
Member

mraleph commented Sep 22, 2018

We would need more information to diagnose this.

Can you edit operator[] in the class ColorSwatch (in file flutter/packages/flutter/lib/src/painting/colors.dart) to do the following:

  /// Returns an element of the swatch table.
  Color operator [](T index) {
    print(">>> Invoked ColorSwatch[$index]:  ${index.runtimeType} / ${index.hashCode}"); 
    return _swatch[index];
  }

then flutter clean and rerun the application?

@IhorKlimov
Copy link
Author

IhorKlimov commented Sep 22, 2018

@maguinis Here's the updated logcat

09-22 23:23:52.173 24834 24873 I flutter : >>> Invoked ColorSwatch[100]:  int / 100
09-22 23:23:52.173 24834 24873 I flutter : >>> Invoked ColorSwatch[700]:  int / 700
09-22 23:23:52.173 24834 24873 I flutter : >>> Invoked ColorSwatch[600]:  int / 600
09-22 23:23:52.173 24834 24873 I flutter : >>> Invoked ColorSwatch[500]:  int / 500
09-22 23:23:52.173 24834 24873 I flutter : >>> Invoked ColorSwatch[50]:  int / 50
09-22 23:23:52.174 24834 24873 I flutter : ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
09-22 23:23:52.175 24834 24873 I flutter : The following NoSuchMethodError was thrown building Application(dirty):
09-22 23:23:52.175 24834 24873 I flutter : The method '&' was called on null.
09-22 23:23:52.175 24834 24873 I flutter : Receiver: null
09-22 23:23:52.175 24834 24873 I flutter : Tried calling: &()
09-22 23:23:52.175 24834 24873 I flutter : 
09-22 23:23:52.175 24834 24873 I flutter : When the exception was thrown, this was the stack:
09-22 23:23:52.176 24834 24873 I flutter : #0      _HashBase._hashPattern (dart:collection/runtime/libcompact_hash.dart:98)
09-22 23:23:52.176 24834 24873 I flutter : #1      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin._getValueOrData (dart:collection/runtime/libcompact_hash.dart:329)
09-22 23:23:52.176 24834 24873 I flutter : #2      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.[] (dart:collection/runtime/libcompact_hash.dart:351)
09-22 23:23:52.176 24834 24873 I flutter : #3      ColorSwatch.[] (package:flutter/src/painting/colors.dart:552)
09-22 23:23:52.176 24834 24873 I flutter : #4      new ThemeData. (package:flutter/src/material/theme_data.dart:160)
09-22 23:23:52.176 24834 24873 I flutter : #5      Application.build (package:shenanny/main.dart:33)
09-22 23:23:52.176 24834 24873 I flutter : #6      StatelessElement.build (package:flutter/src/widgets/framework.dart:3731)
09-22 23:23:52.176 24834 24873 I flutter : #7      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3678)
09-22 23:23:52.177 24834 24873 I flutter : #8      Element.rebuild (package:flutter/src/widgets/framework.dart:3531)
09-22 23:23:52.177 24834 24873 I flutter : #9      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3658)
09-22 23:23:52.177 24834 24873 I flutter : #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3653)
09-22 23:23:52.177 24834 24873 I flutter : #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2937)
09-22 23:23:52.177 24834 24873 I flutter : #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2740)
09-22 23:23:52.177 24834 24873 I flutter : #13     RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:881)
09-22 23:23:52.177 24834 24873 I flutter : #14     RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:852)
09-22 23:23:52.177 24834 24873 I flutter : #15     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:798)
09-22 23:23:52.177 24834 24873 I flutter : #16     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2253)
09-22 23:23:52.177 24834 24873 I flutter : #17     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:797)
09-22 23:23:52.177 24834 24873 I flutter : #18     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:689)
09-22 23:23:52.177 24834 24873 I flutter : #19     runApp (package:flutter/src/widgets/binding.dart:728)
09-22 23:23:52.177 24834 24873 I flutter : #20     main (package:shenanny/main.dart:13)
09-22 23:23:52.177 24834 24873 I flutter : #21     _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289)
09-22 23:23:52.177 24834 24873 I flutter : #22     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171)
09-22 23:23:52.177 24834 24873 I flutter : ════════════════════════════════════════════════════════════════════════════════════════════════════

It didn't seem that there was anything wrong. After debugging a bit more I found the issue. I had my primarySwatch declared without a const keyword, like this

static  MaterialColor primarySwatch = MaterialColor(
  0xFFAE4244,
  <int, Color>{
    50: Color(0xFFECE6E6),
    100: Color(0xFFD0C1C1),
    200: Color(0xFFB19798),
    300: Color(0xFF916D6E),
    400: Color(0xFF7A4E4F),
    500: Color(0xFFAE4244),
    600: Color(0xFF5A2A2B),
    700: Color(0xFF502324),
    800: Color(0xFF461D1E),
    900: Color(0xFF341213)
  },
);

After adding const in the declaration it started working just fine. Strange that it occurred only on release builds.

@mraleph
Copy link
Member

mraleph commented Sep 22, 2018

After adding const in the declaration it started working just fine. Strange that it occurred only on release builds.

Whatever we are seeing this is totally not an expected effect from omitting the const keyword - the null pointer exception occurs in the location where it should be impossible.

Thanks to your pointer I was able to reproduce this error now and I am looking into this.

@mraleph mraleph self-assigned this Sep 22, 2018
@mraleph
Copy link
Member

mraleph commented Sep 22, 2018

Reduction:

class X {
  final Map<int, String> data;
  const X(this.data);
}

const f = X({ 1: "ok-f" });
final g = X({ 1: "ok-g" });

void main() {
  print(f.data[1]);
  print(g.data[1]);
}
╭─vegorov@volhv ~/src/dart/sdk ‹master›
╰─$ pkg/vm/tool/precompiler2 /tmp/z.dart /tmp/z.aot && out/ReleaseX64/dart_precompiled_runtime /tmp/z.aot
Unhandled exception:
NoSuchMethodError: The method '&' was called on null.
Receiver: null
Tried calling: &()
#0      _HashBase._hashPattern (dart:collection/runtime/libcompact_hash.dart:98)
#1      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin._getValueOrData (dart:collection/runtime/libcompact_hash.dart:329)
#2      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.[] (dart:collection/runtime/libcompact_hash.dart:351)
#3      main (file:///tmp/z.dart:2)
#4      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171)

The bug is in the interaction between TFA and backend field type inference, that does not take constants into account. TFA provides inferred type for data parameter of the constructor X which says that data is always an normal map. Backend field type inference then infers from that that X.data is always a normal map, and we end up statically linking f.data[] to the LinkedHashMap.[] - which is incorrect because there is a constant in the heap that has an immutable map as a field.

assigning to @alexmarkov

@mraleph mraleph assigned alexmarkov and unassigned mraleph Sep 22, 2018
@zoechi zoechi added c: crash Stack traces logged to the console dependency: dart Dart team may need to help us labels Sep 23, 2018
@zoechi zoechi added this to the Goals milestone Sep 23, 2018
@alexmarkov
Copy link
Contributor

Constant objects are evaluated and boiled down to a list of field-value pairs, so there are no more constructor invocations involved. For the remaining constructor invocations TFA yields correct results here. So the problem is in the incorrect type inference of final field types in backend, which doesn't account for already evaluated constant objects.

Maybe instead of fixing that limited type inference in the backend we should replace it with results from TFA.

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Sep 25, 2018
…ompiler.cc

Type inference for final fields in precompiler.cc is limited and
does not properly handle constant objects.

This change hooks up field types inferred by TFA and removes the
inference in precompiler.cc.

Fixes: flutter/flutter#22131

Change-Id: Ida65cd211074623928bb2a7d48dc58d5e53511b8
Reviewed-on: https://dart-review.googlesource.com/76562
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
@alexmarkov
Copy link
Contributor

The fix landed in Dart SDK (dart-lang/sdk@f81709c). Incorrect analysis is removed and replaced with results of TFA. Keeping the issue open until the fix is rolled into Flutter.

@zoechi zoechi added the waiting for PR to land (fixed) A fix is in flight label Sep 26, 2018
@alexmarkov
Copy link
Contributor

The fix was rolled to Flutter in aef9804.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: crash Stack traces logged to the console dependency: dart Dart team may need to help us waiting for PR to land (fixed) A fix is in flight
Projects
None yet
Development

No branches or pull requests

4 participants