Open insinfo opened 10 months ago
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
/// 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>{};
}
I did a test here using dart 2.10.5, installed webdev 2.7.1 and stagehand 3.3.11 and created a new project with "stagehand web-angular" and ran it with "webdev serve" and it worked normally with angular 6.0.0
With dart 2.12.4 and angular 6.0.0 and webdev 2.7.2 I get the error below
PS C:\my_projects_dart\teste_bug> cls
PS C:\my_projects_dart\teste_bug> webdev serve
[INFO] Building new asset graph completed, took 1.4s
[INFO] Checking for unexpected pre-existing outputs. completed, took 1ms
[INFO] Serving `web` on http://127.0.0.1:8080
[SEVERE] angular:angular on web/main.dart: NoSuchMethodError: The method 'toIntValue' was called on null.
Receiver: null
Tried calling: toIntValue()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 BestPracticesVerifier._targetKindsFor (package:analyzer/src/error/best_practices_verifier.dart:1554:52)
#2 BestPracticesVerifier.visitAnnotation (package:analyzer/src/error/best_practices_verifier.dart:249:17)
#3 AnnotationImpl.accept (package:analyzer/src/dart/ast/ast.dart:281:49)
#4 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7553:20)
#5 AnnotatedNodeImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:149:17)
#6 MethodDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6980:11)
#7 RecursiveAstVisitor.visitMethodDeclaration (package:analyzer/dart/ast/visitor.dart:1067:10)
#8 BestPracticesVerifier.visitMethodDeclaration (package:analyzer/src/error/best_practices_verifier.dart:586:13)
#9 MethodDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:6976:49)
#10 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7553:20)
#11 ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1552:13)
#12 RecursiveAstVisitor.visitClassDeclaration (package:analyzer/dart/ast/visitor.dart:707:10)
#13 BestPracticesVerifier.visitClassDeclaration (package:analyzer/src/error/best_practices_verifier.dart:321:13)
#14 ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1522:49)
#15 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7553:20)
#16 CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2120:21)
#17 RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:731:10)
#18 CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2113:49)
#19 LibraryAnalyzer._computeHints (package:analyzer/src/dart/analysis/library_analyzer.dart:282:10)
#20 LibraryAnalyzer.analyzeSync.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:167:9)
#21 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
#22 LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:166:13)
#23 LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:107:12)
#24 AnalysisDriver._computeAnalysisResult2.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1317:63)
#25 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#26 AnalysisDriver._computeAnalysisResult2 (package:analyzer/src/dart/analysis/driver.dart:1294:20)
#27 AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1247:14)
#28 _rootRun (dart:async/zone.dart:1354:13)
#29 _CustomZone.run (dart:async/zone.dart:1258:19)
#30 _runZoned (dart:async/zone.dart:1788:10)
#31 runZoned (dart:async/zone.dart:1710:10)
#32 NullSafetyUnderstandingFlag.enableNullSafetyTypes (package:analyzer/dart/element/null_safety_understanding_flag.dart:42:12)
#33 AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1246:40)
#34 AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1372:41)
#35 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:979:20)
#36 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2013:24)
<asynchronous suspension>
[WARNING] No actions completed for 15.0s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.0s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.0s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.0s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waiting on:
- angular:angular on package:angular/src/core/linker/component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service.dart
- angular:angular on package:angular/src/core/linker/dynamic_component_loader.dart
- angular:angular on package:angular/src/security/dom_sanitization_service_impl.dart
- angular:angular on package:angular/src/security/sanitization_service.dart
.. and 15 more
[WARNING] No actions completed for 15.1s, waitin
This is very strange because all my Angular 6.0.0 projects normally ran on Dart 2.12.4 until last month
see that the error is exactly in kindObject.getField('index') which is returning null
These are fairly old versions of Dart (~2.10) and analyzer (~4.7.0). We don't generally backport bug fixes. I recommend finding a way to use newer analyzer releases, hopefully >= 6.0.0.
I also ran into what seems like the same issue on Dart 2.18.7. Specifically, resolving to meta>=1.10.0
and test >=1.21.2
would cause any files with @TestOn
annotations in them to silently fail to analyze, as if they were excluded.
This particular issue seemed to be related to by the the addition of @Target({TargetKind.library})
to class TestOn
in test 1.21.2, and the change of TargetKind
from an enum to a class in meta 1.10.0.
No errors were surfaced via dart analyze
or in the IDE (and syntax highlighting also wouldn't update), but if you went to the analyzer diagnostics page from your IDE and clicked on the AST link for the file, you'd get pretty much the same error as this issue's description:
Null check operator used on a null value
#0 ElementAnnotationExtensions.targetKinds (package:analyzer/src/dart/element/extensions.dart:42:51)
...
Things that fixed it:
analyzer
)Since Dart 2.19 fixed it, I'm fine with that being the path forward, since we're in the process of upgrading the affected packages anyways.
@insinfo Perhaps restricting to a lower meta
or test
could help you work around the issue? It looks like meta 1.10.0 was published on Sep 6, which seems to line up with when things stopped working for you.
For posterity, I just confirmed that other annotations that use TargetKind exhibit the same issue as TestOn
, which includes many of the annotations in the meta package itself (@mustCallSuper
, @mustBeOverridden
, and @useResult
) and several other annotations from the test package.
So, restricting to meta 1.9.1 or lower is the best option to avoid this issue.
@greglittlefield-wf
the first moment I detected this problem I just created a repository with the analyzer and adding null checking and applying with dependency_overrides
dependency_overrides:
analyzer:
git:
url: https://github.com/insinfo/analyzer-4.7.0
ref: main
This problem affected all the projects I work on ranging from Dart 2.12 - 2.18.7, it just didn't affect Dart 2.10 projects
I think the change made in the meta 1.10.0 package that transformed TargetKind enum to a class was a big mistake, I think this change should have been published as meta 2.0.0 as a compatibility break, to avoid these problems
I've been working on an AngularDart project of mine every day, and today I started getting this error "Null check operator used on a null value #0 ElementAnnotationExtensions.targetKinds"
I created a simple project to demonstrate the problem
https://github.com/insinfo/dart_bug_demo
https://github.com/angulardart-community/angular/issues/67