Verifier crashes on a lambda whose parameter type cannot be resolved (classes not on the classpath)

未關閉
#396 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
半天
新手友好度
50/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
java
領域
tooling

研究方向

The crash is in Context.addVarToContext (Context.java:193), reached from RefinementTypeChecker.visitCtLambda (RefinementTypeChecker.java:423) when a lambda parameter's type is null. Start by reading those two methods and deciding how an unresolved parameter type should be represented. Done when the minimal reproducer with the unresolvable org.example.missing.Request no longer throws and reports the expected verification result.

由索引模型根據 Issue 內容生成。

描述

bug real-world-finding

Impact: verification stops with an internal error on a lambda whose parameter type comes from a class that is not on the classpath: 2 of the 53 real-world files below.

Description

When a lambda is passed to a method of an unresolved type, Spoon cannot infer the lambda parameter's type, and RefinementTypeChecker.visitCtLambda adds the parameter with a null type: Context.addVarToContext then calls getSuperclass() on it (Context.java:193). Same null type in Context as #389 (there through addInstanceVariable, from a unary operator), reached from a different construct. A parameter with an unknown type could be added without supertypes.

Minimal reproducer (org.example.missing is not on the classpath)

import org.example.missing.Request;

public class Repro {
    static void print(Request request) {
        request.names().forEach(name -> System.out.println(name));
    }
}

Expected

Correct! Passed Verification. (with the usual "Java compilation encountered issues" warning).

Actual

Exception in thread "main" java.lang.RuntimeException: 
Error while checking CtMethodImpl
  on print(Request request) { 
  at Repro.java:4
  with 
Error while checking CtBlockImpl
  on { 
  at Repro.java:4
  with 
Error while checking CtInvocationImpl
  on request.names().forEach(name -> System.out.println(name)); 
  at Repro.java:5
  with 
Error while checking CtLambdaImpl
  on (name -> System.out.println(name)); 
  at Repro.java:5
  with Cannot invoke "spoon.reflect.reference.CtTypeReference.getSuperclass()" because "type" is null
...
Caused by: java.lang.NullPointerException: Cannot invoke "spoon.reflect.reference.CtTypeReference.getSuperclass()" because "type" is null
	at liquidjava.processor.context.Context.addVarToContext(Context.java:193)
	at liquidjava.processor.refinement_checker.RefinementTypeChecker.visitCtLambda(RefinementTypeChecker.java:423)

Reproduced on main at ad055b49 (liquidjava-verifier 0.0.35).

Real-world files that hit it

  • .forEach(header -> builder.withHeader(header, list(originalRequest.getHeaders(header)))); — atlassian/openapi-request-validator (file)
  • (e -> new StreamSource(e.getXsdAsStream())) — stvzhou/powsybl-core (file)

Context

Found while running LiquidJava on the original repository files of 53 real-world typestate and refinement bugs (the files our study exercises were simplified from). Each file is verified on its own, as a user would verify one file of a project, so the project's other classes and its dependencies are not on the classpath. Related: #388, #389, #390.

主要語言
Java
星號
73
分支
38
平均合併
12 小時 32 分鐘
30 天內合併 PR
45

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。