Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Infinite recursion risk in ToolchainDiscoverer.getCanonicalPath() for root paths

オープン 初心者向け
#171 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@efegokdemir がすでに取り組んでいます。

2026年9月24日 から。

  • #200 @efegokdemir による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
java
領域
build-system

調査の方向性

ToolchainDiscoverer.java:267-273 から始め、JDK の検出中に getCanonicalPath() がどのように使用されているかを調べます。toRealPath() の呼び出しが失敗する root パスと深くネストされたパスを試し、その後、メソッドが再帰、NPE、スタックオーバーフローなしに安全に戻ることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Summary

ToolchainDiscoverer.getCanonicalPath() has a recursive fallback that can cause infinite recursion or stack overflow for root paths where path.getParent() returns null.

Location

ToolchainDiscoverer.java:267-273

https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java#L267-L273

Code

private static Path getCanonicalPath(Path path) {
    try {
        return path.toRealPath();
    } catch (IOException e) {
        return getCanonicalPath(path.getParent()).resolve(path.getFileName());
    }
}

Problem

  1. If path is a root directory (e.g. / on Linux or C:\ on Windows), path.getParent() returns null. The recursive call getCanonicalPath(null) throws NPE.
  2. If path.getParent() itself fails with IOException, this creates infinite recursion leading to stack overflow.
  3. The recursive approach also has no depth limit, so deeply nested paths that fail toRealPath() will recurse until stack overflow.

Impact

JDK discovery scanning directories like / or other root-relative paths could crash Maven with a stack overflow or NPE instead of gracefully skipping the problematic path.

Suggested Fix

Replace recursion with iteration:

private static Path getCanonicalPath(Path path) {
    try {
        return path.toRealPath();
    } catch (IOException e) {
        Path parent = path.getParent();
        if (parent == null) {
            return path;
        }
        return getCanonicalPath(parent).resolve(path.getFileName());
    }
}

Or better, use a non-recursive loop with null checks to eliminate the recursion entirely.

主要言語
Java
スター
26
フォーク
32
平均マージ
1日 15時間
マージ済み PR(30日)
3

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/maven-toolchains-plugin のほかの issue

apache/maven-toolchains-plugin の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。