google / reflectable.dart

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.
https://pub.dev/packages/reflectable
BSD 3-Clause "New" or "Revised" License
381 stars 57 forks source link

Error: "Null check operator used on a null value" while using `reflectedTypeCapability` #253

Closed salah-rashad closed 3 years ago

salah-rashad commented 3 years ago

Hi, first of all, I would like to apologize for my bad English, it's not my native language.

So, I was trying to reflect on a Class that extends from an abstract class, everything is okay when I'm NOT using reflectedTypeCapability, but when I do then run the build runner again I get this error:

Null check operator used on a null value

console output ``` PS F:\PROJECTS\flamer> flutter pub run build_runner build -v [ +80 ms] executing: [C:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H [ +64 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H [ +1 ms] f4abaa0735eba4dfd8f33f73363911d63931fe03 [ +1 ms] executing: [C:\flutter/] git tag --points-at f4abaa0735eba4dfd8f33f73363911d63931fe03 [ +50 ms] Exit code 0 from: git tag --points-at f4abaa0735eba4dfd8f33f73363911d63931fe03 [ ] 2.2.3 [ +8 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref --symbolic @{u} [ +76 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u} [ +1 ms] origin/stable [ +1 ms] executing: [C:\flutter/] git ls-remote --get-url origin [ +44 ms] Exit code 0 from: git ls-remote --get-url origin [ +1 ms] https://github.com/flutter/flutter.git [ +151 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref HEAD [ +42 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD [ ] stable [ +113 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ +3 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ +70 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update. [ ] Artifact Instance of 'GradleWrapper' is not required, skipping update. [ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ ] Artifact Instance of 'FlutterSdk' is not required, skipping update. [ ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update. [ ] Artifact Instance of 'PubDependencies' is not required, skipping update. [ +42 ms] Using C:\flutter\.pub-cache for the pub cache. [ ] executing: C:\flutter\bin\cache\dart-sdk\bin\pub run build_runner build -v [INFO] Entrypoint:Generating build script... [INFO] Entrypoint:Generating build script completed, took 557ms [INFO] BuildDefinition:Initializing inputs [INFO] BuildDefinition:Reading cached asset graph... [INFO] BuildDefinition:Reading cached asset graph completed, took 93ms [INFO] BuildDefinition:Checking for updates since last build... [INFO] BuildDefinition:Checking for updates since last build completed, took 997ms [INFO] Build:Running build... [INFO] Build:Running build completed, took 41ms [INFO] Build:Caching finalized dependency graph... [INFO] Build:Caching finalized dependency graph completed, took 55ms [SEVERE] reflectable:reflectable on lib/main.dart (cached): Null check operator used on a null value package:reflectable/src/builder_implementation.dart 5477:79 _formatDiagnosticMessage package:reflectable/src/builder_implementation.dart 1909:19 _ReflectorDomain._typeCodeOfTypeArgument.fail package:reflectable/src/builder_implementation.dart 1979:41 _ReflectorDomain._typeCodeOfTypeArgument package:reflectable/src/builder_implementation.dart 2082:37 _ReflectorDomain._typeCodeOfClass package:reflectable/src/builder_implementation.dart 1105:27 _ReflectorDomain._generateCode package:reflectable/src/builder_implementation.dart 145:11 ReflectionWorld.generateCode package:reflectable/src/builder_implementation.dart 4161:19 BuilderImplementation._generateNewEntryPoint package:reflectable/src/builder_implementation.dart 4269:35 BuilderImplementation.buildMirrorLibrary package:reflectable/reflectable_builder.dart 29:27 ReflectableBuilder.build [SEVERE] Build: Failed after 143ms [+4465 ms] "flutter run" took 4,632ms. [ +6 ms] pub finished with exit code 1 [ +3 ms] #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) #1 _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:368:7) #2 PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:241:5) #3 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1043:27) #4 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #5 CommandRunner.runCommand (package:args/command_runner.dart:196:13) #6 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:284:9) #7 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #8 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:232:5) #9 run.. (package:flutter_tools/runner.dart:62:9) #10 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #11 main (package:flutter_tools/executable.dart:91:3) [ +272 ms] ensureAnalyticsSent: 266ms [ +1 ms] Running shutdown hooks [ ] Shutdown hooks complete [ ] exiting with code 1 ```
flutter doctor -v ``` PS F:\PROJECTS\flamer> flutter doctor -v [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1110], locale en-US) • Flutter version 2.2.3 at C:\flutter • Framework revision f4abaa0735 (3 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4 [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\AndroidSDK • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = C:\AndroidSDK • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.3) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.10.31424.327 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = C:\Program Files\Android\Android Studio • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) [√] VS Code (version 1.58.2) • VS Code at C:\Users\sla7r\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.24.0 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19043.1110] • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.164 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.67 • No issues found! ```
// reflector.dart
class Reflector extends Reflectable {
  const Reflector()
      : super(
          invokingCapability,
          typingCapability,
          reflectedTypeCapability,
          typeRelationsCapability,
        );
}

const textComponentReflector = const Reflector();
// main.dart
...
import 'main.reflectable.dart';

Future<void> main() async {
  initializeReflectable();

  await Storage.initialize();
  runApp(MyApp());
}
...

Thanks.

eernstg commented 3 years ago

Thanks for the report! Fixed in https://github.com/google/reflectable.dart/pull/254.