Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflowError related to JLS type inference #6421

Closed
jyoo980 opened this issue Jan 25, 2024 · 1 comment · Fixed by #6517
Closed

StackOverflowError related to JLS type inference #6421

jyoo980 opened this issue Jan 25, 2024 · 1 comment · Fixed by #6517
Assignees

Comments

@jyoo980
Copy link
Contributor

jyoo980 commented Jan 25, 2024

Issue

Running the latest version of the Checker Framework (head of master should be sufficient) appears to crash with a StackOverflowError related to type inference. A sample log is available here, and the steps to reproduce this error are below.

I have attempted to isolate the commit that introduced this error via git bisect, which yielded this commit as the most likely culprit.

Steps to Reproduce

# Clone the sample program that induces the error, and check out the branch with the local CF config changes
git clone git@github.com:jyoo980/fixture-monkey.git
cd fixture-monkey/
git checkout yoo/local-cf

# Ensure that your local copy of the Checker Framework is up-to-date and run it on the program
./gradlew -PcfLocal compileJava

Expected output
The program should type-check (not cleanly, though) and the CF should not crash.

Actual output
The CF crashes; the log is available here. Running the same program with the same command on a prior commit of the Checker Framework (I tested at the commit immediately before) does not crash.

@smillst
Copy link
Member

smillst commented Mar 11, 2024

Here's a small testcase that reproduces this crash.

import java.util.Arrays;
import java.util.List;

public class Issue6421 {

  public static final List<MatcherOperator<ArbitraryIntrospector>> DEFAULT_ARBITRARY_INTROSPECTORS =
      Arrays.asList(
          MatcherOperator.exactTypeMatchOperator(UnidentifiableType.class,
              NullArbitraryIntrospector.INSTANCE),
          MatcherOperator.exactTypeMatchOperator(
              GeneratingWildcardType.class,
              context -> new ArbitraryIntrospectorResult(CombinableArbitrary.from(new Object()))
          )
      );

  public interface ArbitraryIntrospector {
    ArbitraryIntrospectorResult introspect(ArbitraryGeneratorContext context);
  }

  public interface CombinableArbitrary<T> {
    static <T> CombinableArbitrary<T> from(T object) {
      throw new RuntimeException();
    }
  }

  public static final class ArbitraryGeneratorContext {}

  public static final class MatcherOperator<T> {
    public static <T, C> MatcherOperator<T> exactTypeMatchOperator(Class<C> type, T operator) {
      throw new RuntimeException();
    }
  }

  public static class GeneratingWildcardType {}

  public static class UnidentifiableType {}

  public static final class NullArbitraryIntrospector implements ArbitraryIntrospector {

    public static final NullArbitraryIntrospector INSTANCE = new NullArbitraryIntrospector();

    @Override
    public ArbitraryIntrospectorResult introspect(ArbitraryGeneratorContext context) {
      return null;
    }
  }

  public static final class ArbitraryIntrospectorResult {
    public ArbitraryIntrospectorResult(CombinableArbitrary<?> value) {
    }
  }
}

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

Successfully merging a pull request may close this issue.

2 participants