Skip to content

[jnigen] Report an empty config list entry as a config error - #3514

Open
Yusufihsangorgel wants to merge 1 commit into
dart-lang:mainfrom
Yusufihsangorgel:issue-1802-empty-config-entry
Open

[jnigen] Report an empty config list entry as a config error#3514
Yusufihsangorgel wants to merge 1 commit into
dart-lang:mainfrom
Yusufihsangorgel:issue-1802-empty-config-entry

Conversation

@Yusufihsangorgel

Copy link
Copy Markdown
Contributor

Description

An entry left empty under a list key reads as null, and the list it lands in is cast lazily, so nothing fails until something reaches for the element:

Unhandled exception:
type 'Null' is not a subtype of type 'String' in type cast
#0      _CastListBase.[] (dart:_internal/cast.dart:102:46)
#1      ListBase.elementAt (dart:collection/list.dart:43:33)
#2      ListIterator.moveNext (dart:_internal/iterable.dart:371:26)
#3      new Config (package:jnigen/src/config/config_types.dart:277:29)
#4      Config.parseArgs (package:jnigen/src/config/config_types.dart:397:20)

Nothing there names the key or the file, which is what the issue reports.

The entries are now checked where they are read, and the one that is empty is named:

Fatal: Error parsing configuration: Entry 2 of "classes" is empty in the config file.

This covers both list readers, so source_path, class_path and import report the same way rather than reaching optionalPathList and failing there.

The check runs on whichever source won, and only a list read from the file can carry a null: a -D override holds its own strings, so -Dclasses=com.example.Bar still overrides a file with an empty entry.

The test writes its own config file, since -D cannot express an empty entry: the override parser requires a value after =.

Related Issues

Fixes #1802

PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've run dart tool/ci.dart --all locally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevel pubspec.yaml workspace.
  • All existing and new tests are passing. I added new tests to check the change I am making.
  • The PR is actually solving the issue. PRs that don't solve the issue will be closed. Please be respectful of the maintainers' time. If it's not clear what the issue is, feel free to ask questions on the GitHub issue before submitting a PR.
  • I have updated CHANGELOG.md for the relevant packages. (Not needed for small changes such as doc typos).
  • I have updated the pubspec package version if necessary.

On the three unchecked boxes: pkgs/jnigen is not in the toplevel workspace, so dart tool/ci.dart --all does not cover it; I ran the steps from .github/workflows/jnigen.yaml instead. flutter analyze --fatal-infos is clean for the package, and dart format leaves the two files here alone. It does want to reformat three checked-in bindings, but it does that on an untouched checkout too, on the SDK I have. I left the CHANGELOG and the version alone because 0.17.0 is published and opening the next -wip means bumping version in dart_generator.dart to match, which rewrites the header of every checked-in binding. Say the word and I will add both.

An entry left empty under a list key reads as null, and the list it
lands in is cast lazily, so nothing fails until something reaches for
the element: `type 'Null' is not a subtype of type 'String' in type
cast`, from a stack trace that names neither the key nor the file.

Check the entries in `getStringList` and `getPathList` and name the one
that is empty. A list that came from `-D` holds its own strings, so an
override still wins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jnigen crashes on empty string in jnigen.yaml classes: section

1 participant