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

Analyzer crashes when analyzing a package with a different meta version #46183

Closed
simolus3 opened this issue May 29, 2021 · 4 comments
Closed
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@simolus3
Copy link
Contributor

When the analyzer is analyzing a package using a different version of meta than the one it was compiled with, it may crash:

Unhandled exception:
RangeError (index): Invalid value: Not in inclusive range 0..12: 13
#0      List.[] (dart:core-patch/array.dart:268:52)
#1      BestPracticesVerifier._targetKindsFor (package:analyzer/src/error/best_practices_verifier.dart:1601:38)
#2      BestPracticesVerifier.visitAnnotation (package:analyzer/src/error/best_practices_verifier.dart:253:17)
#3      AnnotationImpl.accept (package:analyzer/src/dart/ast/ast.dart:302:50)
#4      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7517:20)
#5      AnnotatedNodeImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:145:17)
#6      ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1537:11)
#7      RecursiveAstVisitor.visitClassDeclaration (package:analyzer/dart/ast/visitor.dart:711:10)
#8      BestPracticesVerifier.visitClassDeclaration (package:analyzer/src/error/best_practices_verifier.dart:323:13)
#9      ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1514:50)
#10     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7517:20)
#11     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2112:21)
#12     RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:735:10)
#13     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2105:50)
#14     LibraryAnalyzer._computeHints (package:analyzer/src/dart/analysis/library_analyzer.dart:276:10)
#15     LibraryAnalyzer.analyzeSync.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:158:9)
#16     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
#17     LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:157:13)
#18     LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:104:12)
#19     AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1315:63)
#20     PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#21     AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1286:20)
#22     AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1369:26)
#23     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:987:20)
#24     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2006:24)
<asynchronous suspension>

#0      AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1344:9)
#1      PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#2      AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1286:20)
#3      AnalysisDriver._computeErrors (package:analyzer/src/dart/analysis/driver.dart:1369:26)
#4      AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:987:20)
#5      AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2006:24)
<asynchronous suspension>

It looks like the culprit is this logic here:

for (var kindObject in value.getField('kinds')!.toSetValue()!) {
var index = kindObject.getField('index')!.toIntValue()!;
kinds.add(TargetKind.values[index]);
}

kindObject.getField('index')!.toIntValue()! refers to the index of the value in the actual meta package used by the code analyzed. However, TargetKind.values may be a different meta version (the one used when the SDK was built). Due to this mismatch, the analyzer may resolve to a wrong TargetKind. If a new meta update adds a new TargetKind with a higher index than what's available in the meta version used to compile the SDK, the analyzer crashes.

To reproduce:

cd /tmp
curl https://storage.googleapis.com/pub-packages/packages/moor-4.3.2.tar.gz --output moor.tar.gz
mkdir moor
cd moor
tar --extract --gzip --file ../moor.tar.gz
dart pub upgrade
dartanalyzer lib

I'll contribute a fix myself, just wanted to report this first.

@simolus3
Copy link
Contributor Author

@vsmenon vsmenon added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 30, 2021
@isoos
Copy link

isoos commented May 31, 2021

Another angle of the same issue, with the Dart SDK 2.13.1:

@simolus3
Copy link
Contributor Author

@isoos analyzer version 1.7.1 depends on meta: >=1.3.0 <1.4.0 which means that the "problematic" version of the meta package can't be selected.

@devoncarew devoncarew added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Jun 1, 2021
@devoncarew
Copy link
Member

Fixed in 8eba520; thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

4 participants