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

[SEVERE] ngdart on web/main.dart: Null check operator used on a null value #0 ElementAnnotationExtensions.targetKinds (package:analyzer/src/dart/element/extensions.dart:44:53) #67

Open
insinfo opened this issue Oct 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@insinfo
Copy link

insinfo commented Oct 3, 2023

Which ng* package(s) are the source of the bug?

ngdart

Which operating system(s) does this bug appear on?

Windows

Which browser(s) does this bug appear on?

Chrome 117.0.5938.132 64 bits

Is this a regression?

Yes

Description

I've been working on an AngularDart project of mine every day, and today I started getting this error "ngdart on web/main.dart: Null check operator used on a null value"

Please provide the steps to reproduce the bug

create a simple angular project and run webdev serve

https://github.com/insinfo/dart_bug_demo

Please provide the exception or error you saw

PS C:\MyDartProjects\dart_bug_demo> webdev serve
[INFO] Building new asset graph completed, took 1.7s
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms
[INFO] Serving `web` on http://127.0.0.1:8080
[SEVERE] ngdart on web/main.dart: Null check operator used on a null value
#0      ElementAnnotationExtensions.targetKinds (package:analyzer/src/dart/element/extensions.dart:44:53)
#1      BestPracticesVerifier.visitAnnotation (package:analyzer/src/error/best_practices_verifier.dart:323:25)
#2      AnnotationImpl.accept (package:analyzer/src/dart/ast/ast.dart:318:50)
#3      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8777:20)
#4      AnnotatedNodeImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:154:17)
#5      ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1823:11)
#6      RecursiveAstVisitor.visitClassDeclaration (package:analyzer/dart/ast/visitor.dart:793:10)
#7      BestPracticesVerifier.visitClassDeclaration (package:analyzer/src/error/best_practices_verifier.dart:404:13)
#8      ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1799:50)
#9      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:8777:20)
#10     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2455:21)
#11     RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:817:10)
#12     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2448:50)
#13     LibraryAnalyzer._computeHints (package:analyzer/src/dart/analysis/library_analyzer.dart:344:10)
#14     LibraryAnalyzer._computeDiagnostics.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:274:9)
#15     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
#16     LibraryAnalyzer._computeDiagnostics (package:analyzer/src/dart/analysis/library_analyzer.dart:273:13)        
#17     LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:92:5)
#18     AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1373:11)
<asynchronous suspension>
#19     PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)
<asynchronous suspension>
#20     AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1410:26)
<asynchronous suspension>
#21     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1118:20)
<asynchronous suspension>
#22     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2171:7)
<asynchronous suspension>


[INFO] 10.7s elapsed, 29/33 actions completed.^CDeseja finalizar o arquivo em lotes (S/N)? s
PS C:\MyDartProjects\dart_bug_demo>

Please provide the dependency environment you discovered this bug in (run dart pub deps -s compact)

PS C:\MyDartProjects\dart_bug_demo> dart pub deps -s compact
Dart SDK 2.18.7
dart_bug_demo 0.0.0

dependencies:
- ngdart 7.1.1 [built_collection built_value collection intl js logging meta stack_trace stream_transform ngast ngcompiler build build_config code_builder csslib path quiver source_gen source_span]

dev dependencies:
- build_runner 2.3.3 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- build_web_compilers 3.2.6 [analyzer archive bazel_worker build build_config build_modules collection glob js logging path pool scratch_space source_maps source_span stack_trace]

transitive dependencies:
- _fe_analyzer_shared 47.0.0 [meta]
- analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- archive 3.4.2 [crypto path pointycastle]
- args 2.4.1
- async 2.11.0 [collection meta]
- bazel_worker 1.0.2 [async protobuf]
- boolean_selector 2.1.1 [source_span string_scanner]
- build 2.3.1 [analyzer async convert crypto glob logging meta path]
- build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 3.1.1 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_modules 4.0.6 [analyzer async bazel_worker build build_config collection crypto glob graphs json_annotation logging path scratch_space stream_transform]
- build_resolvers 2.0.10 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.2.7 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- build_test 2.1.7 [async build build_config build_resolvers crypto glob html logging matcher package_config path stream_transform test test_core watcher]
- built_collection 5.1.1
- built_value 8.6.3 [built_collection collection fixnum meta]
- charcode 1.3.1
- checked_yaml 2.0.2 [json_annotation source_span yaml]
- clock 1.1.1
- code_builder 4.4.0 [built_collection built_value collection matcher meta]
- collection 1.18.0
- convert 3.1.1 [typed_data]
- coverage 1.6.3 [args logging package_config path source_maps stack_trace vm_service]
- crypto 3.0.2 [typed_data]
- csslib 0.17.2 [source_span]
- dart_style 2.2.4 [analyzer args path pub_semver source_span]
- file 6.1.4 [meta path]
- fixnum 1.0.1
- frontend_server_client 3.2.0 [async path]
- glob 2.1.1 [async collection file path string_scanner]
- graphs 2.3.1 [collection]
- html 0.15.3 [csslib source_span]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- io 1.0.4 [meta path string_scanner]
- js 0.6.5 [meta]
- json_annotation 4.8.0 [meta]
- logging 1.1.1
- matcher 0.12.16 [async meta stack_trace term_glyph test_api]
- meta 1.10.0
- mime 1.0.4
- ngast 2.1.4 [charcode collection meta source_span string_scanner]
- ngcompiler 2.1.3 [ngdart ngast analyzer args build build_test code_builder collection csslib dart_style logging meta package_config path source_gen source_span stack_trace]
- node_preamble 2.0.2
- package_config 2.1.0 [path]
- path 1.8.3
- pointycastle 3.7.3 [collection convert js]
- pool 1.5.1 [async stack_trace]
- protobuf 2.1.0 [fixnum collection meta]
- pub_semver 2.1.4 [collection meta]
- pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.2.1 [matcher]
- scratch_space 1.0.1 [build crypto path pool]
- shelf 1.4.1 [async collection http_parser path stack_trace stream_channel]
- shelf_packages_handler 3.0.2 [path shelf shelf_static]
- shelf_static 1.1.2 [convert http_parser mime path shelf]
- shelf_web_socket 1.0.4 [shelf stream_channel web_socket_channel]
- source_gen 1.2.6 [analyzer async build dart_style glob meta path source_span yaml]
- source_map_stack_trace 2.1.1 [path source_maps stack_trace]
- source_maps 0.10.12 [source_span]
- source_span 1.10.0 [collection path term_glyph]
- stack_trace 1.11.1 [path]
- stream_channel 2.1.1 [async]
- stream_transform 2.1.0
- string_scanner 1.2.0 [source_span]
- term_glyph 1.2.1
- test 1.24.3 [analyzer async boolean_selector collection coverage http_multi_server io js node_preamble package_config path pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel typed_data web_socket_channel webkit_inspection_protocol yaml test_api test_core matcher]
- test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- test_core 0.5.3 [analyzer async args boolean_selector collection coverage frontend_server_client glob io meta package_config path pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml test_api]
- timing 1.0.1 [json_annotation]
- typed_data 1.3.2 [collection]
- vm_service 11.2.0
- watcher 1.0.2 [async path]
- web_socket_channel 2.4.0 [async crypto stream_channel]
- webkit_inspection_protocol 1.2.0 [logging]
- yaml 3.1.1 [collection source_span string_scanner]
PS C:\MyDartProjects\dart_bug_demo>

Anything else?

No response

@insinfo insinfo added the bug Something isn't working label Oct 3, 2023
@insinfo
Copy link
Author

insinfo commented Oct 3, 2023

It's strange because it's reporting the problem in this line 44 var index = kindObject.getField('index')!.toIntValue()!;

C:\Users\isaque.neves\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\analyzer-4.7.0\lib\src\dart\element\extensions.dart

If I edit this file by placing an if to check if kindObject.getField('index') != null the problem apparently disappears

after

/// Return the target kinds defined for this [ElementAnnotation].
  Set<TargetKind> get targetKinds {
    final element = this.element;
    InterfaceElement? interfaceElement;
    if (element is PropertyAccessorElement) {
      if (element.isGetter) {
        var type = element.returnType;
        if (type is InterfaceType) {
          interfaceElement = type.element2;
        }
      }
    } else if (element is ConstructorElement) {
      interfaceElement = element.enclosingElement3;
    }
    if (interfaceElement == null) {
      return const <TargetKind>{};
    }
    for (var annotation in interfaceElement.metadata) {
      if (annotation.isTarget) {
        var value = annotation.computeConstantValue()!;
        var kinds = <TargetKind>{};

        for (var kindObject in value.getField('kinds')!.toSetValue()!) {
          // We can't directly translate the index from the analyzed TargetKind
          // constant to TargetKinds.values because the analyzer from the SDK
          // may have been compiled with a different version of pkg:meta.
          // add this if
        if(kindObject.getField('index') != null){
            var index = kindObject.getField('index')!.toIntValue()!;
            var targetKindClass =
                (kindObject.type as InterfaceType).element2 as EnumElementImpl;
            // Instead, map constants to their TargetKind by comparing getter
            // names.
            var getter = targetKindClass.constants[index];
            var name = 'TargetKind.${getter.name}';

            var foundTargetKind = _targetKindsByName[name];
            if (foundTargetKind != null) {
              kinds.add(foundTargetKind);
            }
          }
        }
        return kinds;
      }
    }
    return const <TargetKind>{};
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant