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

Cannot use stubs from jar file; Checker Framework crashes with java.lang.IllegalStateException: zip file closed #6053

Closed
Calvin-L opened this issue Jun 22, 2023 · 5 comments · Fixed by #6056

Comments

@Calvin-L
Copy link
Contributor

The docs say:

The -Astubs argument causes the Checker Framework to read annotations from annotated stub classes in preference to the unannotated original library classes. [...] specifying a directory or .jar file is equivalent to specifying every file in it whose name ends with .astub.

However, reading stubs from a jar file doesn't seem to work.

Quick-and-easy repro script:

#!/usr/bin/env bash

# Settings
# CF_VERSION='3.20.0' # works
# CF_VERSION='3.22.0' # works
# CF_VERSION='3.24.0' # works
# CF_VERSION='3.25.0' # broken?
# CF_VERSION='3.26.0' # broken?
# CF_VERSION='3.28.0' # broken?
# CF_VERSION='3.29.0' # broken?
CF_VERSION='3.35.0' # broken?
GENERATED_FILES=(
    Main.java
    Main.class
    Stubs.astub
    stubs.jar
)

set -ex

# Clean up
rm -rf "${GENERATED_FILES[@]}"

# Download the checker framework
if [[ ! -d "checker-framework-${CF_VERSION}" ]]; then
    curl -LOf "https://checkerframework.org/checker-framework-${CF_VERSION}.zip"
    unzip "checker-framework-${CF_VERSION}.zip"
fi

# Create a stub file and package it in a jar
cat >Stubs.astub <<EOF
EOF
jar cvf stubs.jar Stubs.astub

# Create a Main class
cat >Main.java <<EOF
public class Main {
    public static void main(String[] args) {
    }
}
EOF

# Try to compile it
CF_ARGV=(
    # -processor org.checkerframework.checker.nullness.NullnessChecker
    -processor org.checkerframework.checker.lock.LockChecker
    # -processor org.checkerframework.checker.resourceleak.ResourceLeakChecker
    -Astubs=stubs.jar
    Main.java
)
exec "./checker-framework-${CF_VERSION}/checker/bin/javac" "${CF_ARGV[@]}"

Running it gives me the following error:

error: Error when invoking constructor org.checkerframework.checker.lock.LockVisitor(class org.checkerframework.common.basetype.BaseTypeChecker) on args [org.checkerframework.checker.lock.LockChecker@6d7fc27]; cause: zip file closed
  ; The Checker Framework crashed.  Please report the crash.
  Exception: java.lang.IllegalStateException: zip file closed; java.lang.IllegalStateException: zip file closed
  	at java.base/java.util.zip.ZipFile.ensureOpen(ZipFile.java:831)
  	at java.base/java.util.zip.ZipFile.getManifestName(ZipFile.java:1057)
  	at java.base/java.util.zip.ZipFile$1.getManifestName(ZipFile.java:1100)
  	at java.base/java.util.jar.JarFile.maybeInstantiateVerifier(JarFile.java:723)
  	at java.base/java.util.jar.JarFile.getInputStream(JarFile.java:840)
  	at org.checkerframework.framework.stub.JarEntryAnnotationFileResource.getInputStream(JarEntryAnnotationFileResource.java:34)
  	at org.checkerframework.framework.stub.AnnotationFileElementTypes.parseAnnotationFiles(AnnotationFileElementTypes.java:282)
  	at org.checkerframework.framework.stub.AnnotationFileElementTypes.parseStubFiles(AnnotationFileElementTypes.java:187)
  	at org.checkerframework.framework.type.AnnotatedTypeFactory.parseAnnotationFiles(AnnotatedTypeFactory.java:3839)
  	at org.checkerframework.framework.type.GenericAnnotatedTypeFactory.postInit(GenericAnnotatedTypeFactory.java:409)
  	at org.checkerframework.checker.lock.LockAnnotatedTypeFactory.<init>(LockAnnotatedTypeFactory.java:147)
  	at org.checkerframework.checker.lock.LockVisitor.createTypeFactory(LockVisitor.java:149)
  	at org.checkerframework.checker.lock.LockVisitor.createTypeFactory(LockVisitor.java:73)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:286)
  	at org.checkerframework.common.basetype.BaseTypeVisitor.<init>(BaseTypeVisitor.java:275)
  	at org.checkerframework.checker.lock.LockVisitor.<init>(LockVisitor.java:90)
  	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
  	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
  	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
  	at org.checkerframework.common.basetype.BaseTypeChecker.invokeConstructorFor(BaseTypeChecker.java:338)
  	at org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:249)
  	at org.checkerframework.common.basetype.BaseTypeChecker.createSourceVisitor(BaseTypeChecker.java:92)
  	at org.checkerframework.framework.source.SourceChecker.initChecker(SourceChecker.java:916)
  	at org.checkerframework.common.basetype.BaseTypeChecker.initChecker(BaseTypeChecker.java:114)
  	at org.checkerframework.framework.source.SourceChecker.typeProcessingStart(SourceChecker.java:866)
  	at org.checkerframework.javacutil.AbstractTypeProcessor$AttributionTaskListener.finished(AbstractTypeProcessor.java:165)
  	at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:854)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1394)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1351)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
  	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
  	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
  	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
@mernst
Copy link
Member

mernst commented Jun 26, 2023

The problem is a newly introduced bug in JavaParser: it crashes on empty files.
#6056 fixes this problem.

@mernst
Copy link
Member

mernst commented Jun 26, 2023

Thanks for reporting this!

@Calvin-L
Copy link
Contributor Author

I'm not sure that's the only problem. The Checker Framework throws the IllegalStateException even when the stubs file is not empty.

@mernst
Copy link
Member

mernst commented Jun 27, 2023

@Calvin-L I think this PR may fix the problem with non-empty files as well. Could you please try, either from the master branch or from the release (which will be made on July 3)? Thanks!

@Calvin-L
Copy link
Contributor Author

Yes, it does fix the problem. Thank you. :)

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

Successfully merging a pull request may close this issue.

2 participants