Skip to content

Crash: Null check operator used on a null value #4021

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

Closed
gs0-debiotech opened this issue Mar 21, 2025 · 8 comments · Fixed by #4022
Closed

Crash: Null check operator used on a null value #4021

gs0-debiotech opened this issue Mar 21, 2025 · 8 comments · Fixed by #4022
Assignees
Labels
P3 A lower priority bug or feature request type-ux A user experience or user interface related issue

Comments

@gs0-debiotech
Copy link

gs0-debiotech commented Mar 21, 2025

When running dartdoc on our application, we get the following failure:

$ dartdoc
Documenting app...
Discovering libraries...
Linking elements...
Precaching local docs for 151614 elements...
Initialized dartdoc with 366 libraries
[...snip...]
Generating docs for library data/dao/app_database_dao.dart from file:///builds/app/lib/data/dao/app_database_dao.dart...
dartdoc 8.3.3 (/root/.pub-cache/global_packages/dartdoc/bin/dartdoc.dart-3.7.0.snapshot) failed: Null check operator used on a null value
#0      Prefix.associatedLibrary (package:dartdoc/src/model/prefix.dart:30:54)
#1      Prefix.associatedLibrary (package:dartdoc/src/model/prefix.dart)
#2      Prefix.canonicalModelElement (package:dartdoc/src/model/prefix.dart:42:41)
#3      Prefix.href (package:dartdoc/src/model/prefix.dart:51:23)
#4      PackageGraph.allHrefs (package:dartdoc/src/model/package_graph.dart:599:33)
#5      new Validator (package:dartdoc/src/validator.dart:38:32)
#6      Dartdoc.generateDocsBase (package:dartdoc/src/dartdoc.dart:209:7)
<asynchronous suspension>
#7      Dartdoc.generateDocs (package:dartdoc/src/dartdoc.dart:241:24)
<asynchronous suspension>
#8      Dartdoc.executeGuarded.<anonymous closure> (package:dartdoc/src/dartdoc.dart:273:9)
<asynchronous suspension>

Link to prefix.dart:30 as of today.

I do not know whether it's linked to the last file read. In case it is, here is the code:

import 'dart:io';

import 'package:app/data/app_database.dart';
import 'package:drift/drift.dart';

part '../../generated/data/dao/app_database_dao.g.dart';

@DriftAccessor()
class AppDatabaseDao extends DatabaseAccessor<AppDatabase> with _$AppDatabaseDaoMixin {
  AppDatabaseDao(super.attachedDatabase);

  Future<void> exportInto(File file) async {
    await file.parent.create(recursive: true);
    await customStatement('VACUUM INTO ?', [file.path]);
  }
}

When checking since when it fails in our pipeline, I do not see anything special in the corresponding commit: only changes in the Dart code, few annotations used (@Freezed(toStringOverride), but nothing related to the tooling.

For context, it's running in a Linux gitlab worker, using the flutter:3.27.1 container from CirrusLabs up to flutter:3.29.1. The setup runs dart pub global activate dartdoc (which ends with Activated dartdoc 8.3.3, and the command is dartdoc.

I tried to replicate it locally (with Flutter 3.29.1 on macOS), and the doc generation works correctly, without a crash.

@srawlins
Copy link
Member

That's funny that you have a prefix.dart as well. But the stack trace is referring to prefix.dart in dartdoc.

@srawlins
Copy link
Member

My best guess is that on GitLab, the code-generation step has not been run yet. dartdoc is looking for an imported library and not finding it.

@srawlins srawlins added type-ux A user experience or user interface related issue P3 A lower priority bug or feature request labels Mar 21, 2025
@srawlins srawlins self-assigned this Mar 21, 2025
@gs0-debiotech
Copy link
Author

That's funny that you have a prefix.dart as well. But the stack trace is referring to prefix.dart in dartdoc.

I'm not exactly sure what you mean. I do not have any "prefix" in my codebase, besides some prefixIcon (or the word "prefix" in the doc-comments).

Thank you for having a look on my issue! Is there an easy way for me to test the fix in your MR?

@srawlins
Copy link
Member

Oh I thought the code you showed, with @DriftAccessor(), was from a prefix.dart file. I misread, and didn't click the link.

@srawlins
Copy link
Member

Is there an easy way for me to test the fix in your MR?

You can run dartdoc from the git branch, or from the main branch when it lands. Maybe something like this.

@gs0-debiotech
Copy link
Author

gs0-debiotech commented Mar 25, 2025

Is it OK if I continue the discussion here, despite the closed issue?

I've tried the commit f41bd3a from main:

$ dart pub global activate --source git https://github.com/dart-lang/dartdoc/ --git-ref f41bd3ab4bd34c048f2c803174f16bc128acadaa
Resolving dependencies...
Downloading packages...
+ _fe_analyzer_shared 80.0.0
+ analyzer 7.3.0
+ args 2.7.0
+ async 2.13.0
+ collection 1.19.1
+ convert 3.1.2
+ crypto 3.0.6
+ csslib 1.0.2
+ dartdoc 8.3.3 from git https://github.com/dart-lang/dartdoc/ at f41bd3
+ file 7.0.1
+ glob 2.1.3
+ html 0.15.5
+ logging 1.3.0
+ markdown 7.3.0
+ meta 1.16.0
+ package_config 2.2.0
+ path 1.9.1
+ pub_semver 2.2.0
+ source_span 1.10.1
+ string_scanner 1.4.1
+ term_glyph 1.2.2
+ typed_data 1.4.0
+ watcher 1.1.1
+ yaml 3.1.3
Building package executables...
Built dartdoc:dartdoc.
Installed executable dartdoc.
Activated dartdoc 8.3.3 from Git repository "https://github.com/dart-lang/dartdoc/".
$ dartdoc
Documenting app...
Discovering libraries...
Linking elements...
Precaching local docs for 152133 elements...
Initialized dartdoc with 378 libraries
[...snip...]
Generating docs for library data/dao/app_database_dao.dart from file:///builds/app/lib/data/dao/app_database_dao.dart...
dartdoc 8.3.3 (/root/.pub-cache/global_packages/dartdoc/bin/dartdoc.dart-3.7.0.snapshot) failed: Bad state: Unexpected null LibraryElement2 for imported library at Instance of 'DirectiveUriWithRelativeUriImpl'
#0      Prefix._importedLibraryElement (package:dartdoc/src/model/prefix.dart:39:7)
#1      Prefix.associatedLibrary (package:dartdoc/src/model/prefix.dart:29:26)
#2      Prefix.associatedLibrary (package:dartdoc/src/model/prefix.dart)
#3      Prefix.canonicalModelElement (package:dartdoc/src/model/prefix.dart:47:41)
#4      Prefix.href (package:dartdoc/src/model/prefix.dart:56:23)
#5      PackageGraph.allHrefs (package:dartdoc/src/model/package_graph.dart:599:33)
#6      new Validator (package:dartdoc/src/validator.dart:38:32)
#7      Dartdoc.generateDocsBase (package:dartdoc/src/dartdoc.dart:209:7)
<asynchronous suspension>
#8      Dartdoc.generateDocs (package:dartdoc/src/dartdoc.dart:241:24)
<asynchronous suspension>
#9      Dartdoc.executeGuarded.<anonymous closure> (package:dartdoc/src/dartdoc.dart:273:9)
<asynchronous suspension>

Unfortunately, the doc still cannot be generated.

@srawlins
Copy link
Member

The change I made will not allow any new docs to be generated. It's just debugging info.

My best guess is that on GitLab, the code-generation step has not been run yet. dartdoc is looking for an imported library and not finding it.

@gs0-debiotech
Copy link
Author

Thanks you. I've noticed that the problem appears locally when running flutter clean before running dartdoc. A simple dart pub get fixed the generation problem (no need to build).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request type-ux A user experience or user interface related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants