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

Ouverte
#396 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
Une demi-journée
Accessibilité débutants
50/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
java
Domaine
tooling

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Java
Étoiles
73
Forks
38
Merge moyen
12 h 32 min
PR mergées (30 j)
45

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de liquid-java/liquidjava

Toutes les issues de liquid-java/liquidjava

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.