JDK-8155701 : The compiler fails with an AssertionError: typeSig ERROR
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2016-04-25
  • Updated: 2024-08-28
  • Resolved: 2022-04-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 19
11.0.17-oracleFixed 17.0.5-oracleFixed 19 b21Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Linux dev-dsk-teuliere-1a-i-eb43600c.eu-west-1.amazon.com 3.2.45-0.6.acc.624.45.283.amzn1acc.x86_64 #1 SMP Fri Nov 21 22:39:25 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Javac fails with an AssertionError when compiling some special files and asks me to submit a bug report.
Here is the exact output:
--------------------------
An exception has occurred in the compiler (1.8.0_77). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: typeSig ERROR
        at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4796)
        at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299)
        at com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:342)
        at com.sun.tools.javac.jvm.ClassWriter.writeCompoundAttribute(ClassWriter.java:891)
        at com.sun.tools.javac.jvm.ClassWriter.writeJavaAnnotations(ClassWriter.java:759)
        at com.sun.tools.javac.jvm.ClassWriter.writeMemberAttrs(ClassWriter.java:628)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1133)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1603)
        at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1693)
        at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1621)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:746)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)
--------------------------

I wrote a small shell script to generate some simple Java files (as small as I could make them) and to compile them, resulting in the error above. See the "Steps to reproduce" section below.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The following shell script can be used to reproduce the issue (explanations follow):
---------------------
#!/bin/sh

# Where to reproduce the bug. Do not choose an existing directory!
WORK_DIR=/tmp/javac-bug
# Configure the paths here
JAVA_HOME=/path/to/jdk1.8
FINDBUGS_JAR=/path/to/findbugs-3.0.0.jar

# Secondary variables
OUTPUT_DIR=$WORK_DIR/output
IMPORTED_FILE=$WORK_DIR/tmp/Foo.java
MAIN_FILE=$WORK_DIR/Bar.java

rm -rf $WORK_DIR

echo "Creating files"

# Create imported file
mkdir -p $WORK_DIR/tmp
cat > $IMPORTED_FILE << EOF
package tmp;

@edu.umd.cs.findbugs.annotations.SuppressWarnings("Foo")
public class Foo {}
EOF

# Create main file
cat > $MAIN_FILE << EOF
import tmp.Foo;

public class Bar {
    public static class InnerBar {
        @edu.umd.cs.findbugs.annotations.SuppressWarnings("Bar")
        public void bar() {}
    }
}
EOF

# Compile
echo "Compiling $IMPORTED_FILE"
mkdir -p "$OUTPUT_DIR"
$JAVA_HOME/bin/javac -d "$OUTPUT_DIR" -classpath "$FINDBUGS_JAR" "$IMPORTED_FILE"
echo "Compiling $MAIN_FILE"
$JAVA_HOME/bin/javac -d "$OUTPUT_DIR" -classpath "$OUTPUT_DIR" "$MAIN_FILE"
---------------------

The script does the following:
 * Set some variables (do not forget to update the first 4 variables to point to the appropriate location)
 * Delete the "work directory" (used to create temporary files)
 * Generate 2 simple classes (tmp.Foo and Bar)
 * Compile them

Note that the first file is compiled with the FindBugs jar in its classpath, whereas the second one is compiled without. This seems to be crucial in order to reproduce the bug.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Instead of an internal error of the compiler, I expect either a successful compilation or a nice error message telling me what is wrong with my program :)
ACTUAL -
Full output:
---------------------
Creating files
Compiling /tmp/javac-bug/tmp/Foo.java
Note: /tmp/javac-bug/tmp/Foo.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Compiling /tmp/javac-bug/Bar.java
An exception has occurred in the compiler (1.8.0_77). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: typeSig ERROR
        at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4796)
        at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299)
        at com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:342)
        at com.sun.tools.javac.jvm.ClassWriter.writeCompoundAttribute(ClassWriter.java:891)
        at com.sun.tools.javac.jvm.ClassWriter.writeJavaAnnotations(ClassWriter.java:759)
        at com.sun.tools.javac.jvm.ClassWriter.writeMemberAttrs(ClassWriter.java:628)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1133)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1603)
        at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1693)
        at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1621)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:746)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)
---------------------


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.AssertionError: typeSig ERROR
        at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4796)
        at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299)
        at com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:342)
        at com.sun.tools.javac.jvm.ClassWriter.writeCompoundAttribute(ClassWriter.java:891)
        at com.sun.tools.javac.jvm.ClassWriter.writeJavaAnnotations(ClassWriter.java:759)
        at com.sun.tools.javac.jvm.ClassWriter.writeMemberAttrs(ClassWriter.java:628)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1133)
        at com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1603)
        at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1693)
        at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1621)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:746)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at com.sun.tools.javac.Main.main(Main.java:42)


No log file is created.

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
The script above generates 2 classes:

tmp/Foo.java:
---------------------
package tmp;

@edu.umd.cs.findbugs.annotations.SuppressWarnings("Foo")
public class Foo {}
---------------------


Bar.java:
---------------------
import tmp.Foo;

public class Bar {
    public static class InnerBar {
        @edu.umd.cs.findbugs.annotations.SuppressWarnings("Bar")
        public void bar() {}
    }
}
---------------------

Please refer to the script for the exact way to compile these files.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
When compiling the second class (Bar.java), adding the FindBugs jar in the classpath works. However, the stack trace does not give any clue as to what is happening (it took me hours to get to a minimal example like this one).

Also, I stumbled into this bug in at least 2 different programs.


Comments
Hi [~vromero] I backported this change, but it causes tools/javac/T6407257.java to fail. That test now reports two errors: T6407257.java:9:1: compiler.err.cyclic.inheritance: T6407257a T6407257.java:11:31: compiler.err.cant.resolve: kindname.class, T6407257a, , 2 errors but the gold file contains only one. Did you encounter this too? Am I missing some other coding I should include in this fix? Thanks!
21-06-2022

Fix request [17u] I backport this for parity with 17.0.5-oracle. A javac fix we should take. Clean backport. Test fails without fix in 17.
21-06-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/453 Date: 2022-06-09 09:38:55 +0000
09-06-2022

Changeset: 1e28fcbc Author: Srikanth Adayapalam <sadayapalam@openjdk.org> Date: 2022-04-29 05:04:23 +0000 URL: https://git.openjdk.java.net/jdk/commit/1e28fcbc5f32103f460bc35235b3cad0cfaa69b5
29-04-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8414 Date: 2022-04-27 05:51:49 +0000
27-04-2022

A more promising second iteration - this passes tier1 and properly surfaces the error in the reproduction scenario. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index b22a1825eab..786f335bc08 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2070,7 +2070,7 @@ public class Resolve { Symbol loadClass(Env<AttrContext> env, Name name, RecoveryLoadClass recoveryLoadClass) { try { ClassSymbol c = finder.loadClass(env.toplevel.modle, name); - return isAccessible(env, c) ? c : new AccessError(env, null, c); + return c.type.isErroneous() && c.classfile == null ? typeNotFound : isAccessible(env, c) ? c : new AccessError(env, null, c); } catch (ClassFinder.BadClassFile err) { return new BadClassFileError(err); } catch (CompletionFailure ex) {
19-04-2022

Strawman patch: diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 84195274d41..6c2c5b64901 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -1937,6 +1937,9 @@ public class ClassReader { } } catch (CompletionFailure ex) { failure = ex; + PackageSymbol ps = container.tsym.packge(); + syms.removeClass(ps.modle, container.tsym.flatName()); + ex.dcfh.classSymbolRemoved((ClassSymbol)container.tsym); } // The method wasn't found: emit a warning and recover JavaFileObject prevSource = log.useSource(requestingOwner.classfile); This patch causes a compilation error to surface correctly, but is slightly problematic as it messes up model view thereby resulting in one failure test/langtools/tools/javac/processing/model/completionfailure/MissingClassFile.java. Working on an alternate fix.
18-04-2022

Here is an interesting experiment: Start with the following: A.java: public class A {} B.java: public class B { A foo() { return null; } } C.java: public class C { public void foo() { B b = new B(); b.foo(); } } 1. Compile A.java and B.java. 2. Now move/delete A.java and A.class so they are missing C. Compile C.java: $ ~/jdk/jdk-17.0.2/bin/javac -g C.java C.java:4: error: cannot access A b.foo(); ^ class file for A not found 1 error This should be the behavior in the present bug's test case scenario also. The missing class file run into a symbol completion failure that results in a "cannot access A" error correctly. But in the problem scenario, this completion failure is not surfaced (why? is the next thing to figure out), we fail to report the error and on the illusion that all is well proceed to generate code and crash and burn.
07-04-2022

Thanks!
20-04-2018

[~phh] There's no need to reopen the other bug, since that bug number has already been used to push a changeset. However, I have cross-linked the issues.
20-04-2018

Raised to P3, to match the perceived duplicate.
20-04-2018

Xin, our engineer, believes it's an unrelated issue, but we'd be happy to reopen the other bug. He says: The compiler throws an AssertError for unknown type edu.umd.cs.findbugs.annotations.SuppressWarnings. type.getTag() returns "Error" when it tries to write the information into the classfile. You don't need an inner class to reproduce it: it still crashes when you replace class Bar with public class Bar { @edu.umd.cs.findbugs.annotations.SuppressWarnings("Bar") public void bar() {} }
20-04-2018

Reopening on behalf of Xin Liu (xxinliu@amazon.com). This problem still exists in JDK11-ea. Running on OSX 10.12.6, the attached (below, inlined, as well) t.sh script produces: Creating files Compiling /tmp/javac-bug/tmp/Foo.java Note: /tmp/javac-bug/tmp/Foo.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Compiling /tmp/javac-bug/Bar.java An exception has occurred in the compiler (11-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.AssertionError: typeSig ERROR at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5088) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:299) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:342) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeCompoundAttribute(ClassWriter.java:866) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeJavaAnnotations(ClassWriter.java:734) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMemberAttrs(ClassWriter.java:601) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1190) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1661) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1769) at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1687) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:757) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1635) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1603) at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:306) at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165) at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57) at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43) In case the upload of t.sh and findbugs-3.0.0.jar doesn't work, I've inlined t.sh below, and findbugs.3.0.0.jar is available at https://sourceforge.net/projects/findbugs/files/findbugs/3.0.0/. #!/bin/sh # Where to reproduce the bug. Do not choose an existing directory! WORK_DIR=/tmp/javac-bug # Configure the paths here #JAVA_HOME=xxx FINDBUGS_JAR=./findbugs-3.0.0.jar # Secondary variables OUTPUT_DIR=$WORK_DIR/output IMPORTED_FILE=$WORK_DIR/tmp/Foo.java MAIN_FILE=$WORK_DIR/Bar.java rm -rf $WORK_DIR echo "Creating files" # Create imported file mkdir -p $WORK_DIR/tmp cat > $IMPORTED_FILE << EOF package tmp; @edu.umd.cs.findbugs.annotations.SuppressWarnings("Foo") public class Foo {} EOF # Create main file cat > $MAIN_FILE << EOF import tmp.Foo; public class Bar { public static class InnerBar { @edu.umd.cs.findbugs.annotations.SuppressWarnings("Bar") public void bar() {} } } EOF # Compile echo "Compiling $IMPORTED_FILE" mkdir -p "$OUTPUT_DIR" #$JAVA_HOME/bin/javac -d "$OUTPUT_DIR" -classpath "$FINDBUGS_JAR" "$IMPORTED_FILE" javac -d "$OUTPUT_DIR" -classpath "$FINDBUGS_JAR" "$IMPORTED_FILE" echo "Compiling $MAIN_FILE" #$JAVA_HOME/bin/javac -d "$OUTPUT_DIR" -classpath "$OUTPUT_DIR" "$MAIN_FILE" javac -d "$OUTPUT_DIR" -classpath "$OUTPUT_DIR" "$MAIN_FILE"
20-04-2018

Since this issue was previously closed as a duplicate of another (JDK-8132535), perhaps it is that other bug that ought to be reopened; not this one.
20-04-2018

This is an duplicate issue of JDK-8132535
29-04-2016