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

shortenFullyQualifiedTypes corrupts method references on fields (x.field::m -> bogus import x.field)

オープン
#3,133 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

2026年10月6日 から。

  • #3134 @maxandersen による — オープン

評価

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

調査の方向性

Start by reading the implementation of shortenFullyQualifiedTypes() added in #3005 and the related tests; the issue does not name their file paths. Reproduce with the supplied Java example and run spotlessApply followed by compileJava. Done means catalog.aliases::get remains unchanged, no bogus import is added, and a regression test covers the case. A linked open pull request (#3134) indicates work is already underway.

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

説明

Summary

shortenFullyQualifiedTypes() (added in #3005) corrupts a method reference on a field of a local variable. It treats localVar.field::method as if localVar.field were a fully-qualified type, shortens it to field::method, and injects a bogus import localVar.field; — which does not compile.

Because it only manifests on spotlessApply (not the read-only spotlessCheck), a developer runs spotlessApply, commits, and then the project no longer builds.

Version
  • com.diffplug.spotless 8.10.3 (Gradle plugin)
  • JDK 11 / 17 (reproduces on both)
Minimal reproducer

build.gradle:

plugins {
    id 'java'
    id 'com.diffplug.spotless' version '8.10.3'
}
repositories { mavenCentral() }
spotless { java { shortenFullyQualifiedTypes() } }

src/main/java/Example.java:

import java.util.Map;
import java.util.function.Function;

public class Example {
    static class Catalog {
        Map<String, String> aliases;
    }

    String demo(Catalog catalog) {
        return find(catalog.aliases::get);   // method ref on a field of a local var
    }

    String find(Function<String, String> f) {
        return f.apply("x");
    }
}
Steps
./gradlew spotlessApply
./gradlew compileJava
Actual

spotlessApply rewrites the file to:

import java.util.Map;
import java.util.function.Function;
import catalog.aliases;          // <-- bogus import of a non-existent package/type

public class Example {
    ...
    String demo(Catalog catalog) {
        return find(aliases::get);   // <-- qualifier dropped, now unresolved
    }
    ...
}

and compilation fails:

Example.java: error: package catalog does not exist
Expected

catalog.aliases::get is a method reference on a field access of a local variable, not a fully-qualified type reference. It must be left untouched (no shortening, no import added).

Root cause (guess)

The qualifier-resolution doesn't verify that the left-hand side of a qualified name / method-reference scope actually resolves to a type before shortening. Field accesses on locals/params (x.y, x.y::m, x.y.z) are being misclassified as fully-qualified type names. Checking that the qualifier is a type (not a local variable / field expression) before rewriting should fix it.

Found while enabling the step on a real codebase (jbangdev/jbang), where catalog.aliases::get (a Catalog local + Map field) broke the build.

主要言語
Java
スター
5.7k
フォーク
565
平均マージ
2日 2時間
マージ済み PR(30日)
57

環境構築

はじめの一歩

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

diffplug/spotless のほかの issue

diffplug/spotless の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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