Skip to content

Search a directory at most once when symbolic links make it reachable along several paths - #8730

Open
mernst wants to merge 91 commits into
typetools:masterfrom
mernst:annotation-file-symlink-loop
Open

mernst wants to merge 91 commits into
typetools:masterfrom
mernst:annotation-file-symlink-loop

Conversation

@mernst

@mernst mernst commented Nov 30, 2026

Copy link
Copy Markdown
Member

Land after #8588.

When a directory named in -Astubs or -Aajava is searched, each directory under it is searched at most once, even if symbolic links make it reachable along several paths. Previously, a link such as stubs/loop whose target is stubs made the search read each stub file in stubs repeatedly, through loop/, loop/loop/, and so on, until the file system refused to resolve the path. A directory that two links lead to was read twice.

AnnotationFileUtil.forEachAnnotationFile records the real path of each directory that it searches, and skips a directory whose real path it has already recorded.

Tests:

  • AnnotationFileUtilTest.symbolicLinkLoopIsSearchedOnce: a link to an enclosing directory.
  • AnnotationFileUtilTest.directoryReachedTwiceIsSearchedOnce: two links to one directory.

Both tests are skipped on a file system that does not support symbolic links.

mernst and others added 30 commits November 15, 2026 18:15
…ive entries one at a time

* A named archive that cannot be opened yields a warning, rather than a
  line on standard error.
* Every "Could not read" diagnostic for an annotation file is a warning,
  and it includes the exception.
* New `AnnotationFileUtil.forEachAnnotationFile` passes each archive entry
  while the archive is open, so an archive's entries need not all be in
  memory at once.
* Parse an ajava file found on the classpath as a stub file, as is done
  for one found in the file system.

Co-authored-by: Chimaobi Emeka-Iheonu <chimaemekaiheonu@gmail.com>
* Within a directory or archive, a hidden file or directory (one whose
  name starts with "."), such as the `._Foo.astub` file that macOS
  creates, is not read.  A hidden file or directory that is named
  explicitly is read.
* An archive within a directory is not read, and a note says so.
* A named file that is not an archive and lacks the expected extension
  yields a warning.

Co-authored-by: Chimaobi Emeka-Iheonu <chimaemekaiheonu@gmail.com>
…s; do not document -Aajava archives

Also share the -Astubs search rules with -Aajava by cross-reference, and fix Javadoc.
…a parseAnnotationFileResource

* A directory named in -Astubs that cannot be listed yields a warning,
  rather than a line on standard error.
* The classpath branch of parseAnnotationFiles uses
  parseAnnotationFileResource, so it shares the whitespace-only check and
  the "Could not read" warning.
* Name each open JarFile `jarFile`, consistently.
…to annotation-file-search

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileUtil.java
#	framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileUtilTest.java
…ies one at a time

AnnotationFileUtil.forEachAnnotationFile passes each annotation file to its
client, and passes an archive's entries while the archive is open.  An
archive that cannot be opened, or a directory that cannot be listed, yields
a resource whose getInputStream throws, so the client reports it.

Co-authored-by: Chimaobi Emeka-Iheonu <chimaemekaiheonu@gmail.com>
…to annotation-file-archive-read

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileElementTypes.java
…to annotation-file-search

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileUtil.java
… remove unused methods

* Read a classpath annotation file without the JDK's cache of jar files, so the jar is closed.
* Test that an annotation file that starts with much whitespace is parsed, in a file and in an archive.
* Check an annotation file for being whitespace-only without decoding it.
* Remove SystemUtil.isWhitespaceOnly() and AnnotationFileUtil.allAnnotationFiles().
…earch

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileElementTypes.java
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileUtil.java
#	framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileTestUtil.java
#	framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileUtilTest.java
…unlistable subdirectory

An archive within a searched directory is reported only if it contains an
annotation file of the requested type or cannot be opened.  A directory
within a searched directory that cannot be listed yields the same warning
as an unreadable annotation file, rather than a note.  Rename isUserSupplied
to isExplicitlyNamed, since a checker can name a location too.  Tests use
AnnotationFileTestUtil to write archives.
# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileUtil.java
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Annotation-file traversal now filters hidden discovered paths, avoids searching the same real directory more than once, and distinguishes explicitly named archives from archives found during directory searches. The traversal reports skipped archives through a callback when inspection finds a matching entry or cannot open the archive. The parser reports notes for these archives. The manual documents supported stub and ajava path entries and archive handling.

Possibly related PRs

Suggested reviewers: smillst

Change: Bug fix

Merge Risk: Minimal · up to 5eb9c

Annotation-file directory searches now visit each real directory once, skip hidden discovered paths, and report archives found during directory searches without reading them. No merge-blocking issue was identified, and the change has tests for the new behavior.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 852ff83 and 5eb9c60.

Files selected for processing: 6

  • docs/manual/annotating-libraries.tex
  • framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileElementTypes.java
  • framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileUtil.java
  • framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileElementTypesTest.java
  • framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileTestUtil.java
  • framework/src/test/java/org/checkerframework/framework/stub/AnnotationFileUtilTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@mernst

mernst commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant