Skip to content

Explain unsupported class file versions in ikvmc diagnostics - #797

Merged
wasabii merged 13 commits into
mainfrom
claude/clever-hawking-ziehrb
Oct 31, 2026
Merged

wasabii merged 13 commits into
mainfrom
claude/clever-hawking-ziehrb

Conversation

@wasabii

@wasabii wasabii commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #127. Also addresses the confusion in #676, where an H2 2.x (Java 11) jar silently produced an assembly with no types.

Problem

When ikvmc hits class files newer than Java 8, it prints one IKVM0101 warning per class carrying only the raw version number (class format error "55.0"). It never says that IKVM only supports Java 8 (52.0). If every class in a jar fails this way, the build still succeeds and produces an assembly with no types, and users conclude that IkvmReference is broken.

Changes

Importer

  • New IKVM0146 warning, one per input jar, replaces the warning per class:
    4 class(es) in "java11.jar" target Java 11 (class file version 55.0), Java 17 (class file version 61.0) and were skipped; IKVM supports class files up to version 52.0 (Java 8). (first skipped class: "p.A")
  • The per-class detail moves to a new info-level diagnostic, IKVM0010. ikvmc currently filters out info-level messages, so this is only visible through event tracing. That's why the summary names the first skipped class.
  • New IKVM0147 warning when no class from an input could be compiled:
    No classes were compiled from "java11.jar": all 4 class(es) failed to compile, so the output assembly contains no types from it. See the preceding warnings for the reasons.
    It counts every compile failure, not just version failures. It only fires when the input contained class files that were attempted, so a jar with only resources, or one whose classes all come from referenced assemblies, doesn't trigger it.
  • module-info.class and entries under META-INF/versions/ are no longer treated as classes. A Java 8 runtime never loads them as classes, and they caused false warnings (META-INF.versions.11.p.A, Unsupported class version 65.0) on otherwise Java 8 multi-release jars. They stay in the embedded jar as resources, as they did before.
  • A loose .class file passed on the command line keeps its existing IKVM0101 warning, but now with the clearer IKVM wording.

Warning or error for the empty-output case: I chose a warning. The importer's convention is that a class which fails to compile is a warning and the assembly is still produced. Making this one case an error would break builds that tolerate it today, such as a transitive jar that is never actually used. Anyone who wants a hard failure can pass -warnaserror:IKVM0147. The warnings already reach MSBuild through IkvmToolTaskDiagnosticWriter, so IkvmReference users will see them in build output.

Runtime: the exception now matches HotSpot exactly

The exception type and message seen by Java code now match OpenJDK 8 exactly. HotSpot's text comes from hotspot/src/share/vm/classfile/classFileParser.cpp in ext/openjdk, and I checked it by running a JDK 8:

Case Message
named define (p.A) p/A has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
defineClass(null, …), Unsafe.defineAnonymousClass Unsupported class file version 55.0, this version of the Java Runtime only recognizes class file versions up to 52.0

HotSpot uses the same wording for versions that are too old (e.g. 44.0) and for preview versions (61.65535), and IKVM now does too. The name is in internal form (p/A), as in HotSpot.

The exception type changes too. Before, versions IKVM.ByteCode itself rejects (e.g. 255.0) reached Java as java.lang.ClassFormatError: Unsupported class version 255.0.. They are now java.lang.UnsupportedClassVersionError, as on HotSpot. Versions IKVM.ByteCode could read but IKVM rejects already threw UnsupportedClassVersionError, just with the bare 55.0 message. UnsupportedClassVersionError extends ClassFormatError, so existing catches still work.

  • ClassLoader.ReadClass now gets the name passed to defineClass.
  • Unsafe.defineAnonymousClass checks the version before handing the class to the parser. Otherwise its "<Unknown>" placeholder would show up where HotSpot reports no name.
  • The version mapping lives on IKVM.CoreLib.Linking.UnsupportedClassVersionException, which map.xml translates to java.lang.UnsupportedClassVersionError using its message. The exception carries the version and, where known, the class name. FormatJavaMessage produces the HotSpot text for exceptions, and FormatMessage produces the IKVM text used only in importer diagnostics.

Accepted versions now match HotSpot (45.0–52.0)

HotSpot accepts every 45.x class file. IKVM rejected 45.0–45.2 with UnsupportedClassVersionError. Before 45.3, the only format difference is the Code attribute header: u1 max_stack, u1 max_locals, u2 code_length instead of u2, u2, u4 (classFileParser.cpp, parse_method). IKVM.ByteCode always decodes the modern layout, so the linking Method in IKVM.CoreLib now decodes the narrower header itself for those versions, through IKVM.ByteCode's public ClassFormatReader, ExceptionHandlerTable and AttributeTable readers. A Code attribute whose contents don't add up to its declared length is a ClassFormatError, with HotSpot's wording ("Code segment has wrong length in class file …"). The importer uses the same parser, so ikvmc accepts these class files too.

Diagnostics. I added the three entries to Diagnostic.json and regenerated the .g.cs files with the T4 templates. The generator reproduced the checked-in files byte for byte before I made the edit.

Testing

  • IKVM.Tests/Runtime/UnsupportedClassVersionTests (new):
    • defines classes through ClassLoader.defineClass (named and with a null name) and Unsafe.defineAnonymousClass at versions 55.0, 61.65535, 44.0 and 255.0, and asserts the exact HotSpot type and message, captured from OpenJDK 8;
    • defines a hand-written p.Old (static int f() { return 42; }) at 45.0 and 45.2 with the old Code layout, and at 45.3 with the modern one, and invokes f.
  • IKVM.CoreLib.Tests/Linking/UnsupportedClassVersionExceptionTests (new) covers the accepted range, the version-to-Java mapping and both message formats.
  • New tests in IkvmImporterTests build tiny version 52/53/55/61 class files with ClassFileBuilder and import them with -log:json. They check:
    • one IKVM0146 plus IKVM0147 and no IKVM0101 for a jar where every class is too new;
    • no IKVM0147 when some classes compile;
    • no warnings for module-info.class and META-INF/versions/ entries.
  • I couldn't run IKVM.Tests or IKVM.Tools.Importer.Tests locally: building IKVM.Java needs the org.ikvm:java-ref-plugin artifact from GitHub Packages, and the request returned 401 without CI's token. Instead I checked by hand:
    • Runtime: I compiled IKVM.Runtime from this branch against the 8.16.2 package's IKVM.Java.dll and swapped it into a console app on that package.
      • With the 8.16.2 runtime as published: a version 55 class gives UnsupportedClassVersionError: 55.0, a version 255 class gives ClassFormatError: Unsupported class version 255.0., and the 45.0/45.2 classes give UnsupportedClassVersionError: 45.0 / 45.2.
      • With this branch's runtime: the named, null-name and anonymous paths at 55.0, 255.0, 44.0 and 61.65535 all print exactly what JDK 8 prints, and the 45.0, 45.2 and 45.3 classes load and return 42, as they do on JDK 8.
    • Importer: I built ikvmc from this branch and from main and ran both against the 8.16.2 libraries, using real javac output. java11.jar (3 classes at Java 11, 1 at Java 17) on main:
      warning IKVM0101: Unable to compile class "p.A". (class format error "55.0")
      warning IKVM0101: Unable to compile class "p.B". (class format error "55.0")
      warning IKVM0101: Unable to compile class "p.C". (class format error "55.0")
      warning IKVM0101: Unable to compile class "p.D". (class format error "61.0")
      
      On this branch:
      warning IKVM0146: 4 class(es) in "java11.jar" target Java 11 (class file version 55.0), Java 17 (class file version 61.0) and were skipped; IKVM supports class files up to version 52.0 (Java 8). (first skipped class: "p.A")
      warning IKVM0147: No classes were compiled from "java11.jar": all 4 class(es) failed to compile, so the output assembly contains no types from it. See the preceding warnings for the reasons.
      
      Multi-release mixed.jar (a Java 8 class, a Java 9 module-info, and Java 11 classes under META-INF/versions/11): main warns four times; this branch produces no output, compiles p.E, and keeps the versioned entries in the embedded jar. A jar containing the 45.0 p.Old now compiles without warnings.
    • These manual checks predate the merge of main, which moved class file parsing into IKVM.CoreLib. After the merge, IKVM.CoreLib (with its Linking tests), IKVM.Tools.Importer and IKVM.Runtime (against the 8.16.3 IKVM.Java.dll) build, and the CoreLib tests pass.
  • IKVM.Tools.Exporter and IKVM.Runtime-ref build.

Class files newer than Java 8 were reported once per class as a generic
"class format error" carrying only the raw version number, and an input
in which every class failed still produced an assembly with no types and
no further explanation.

- Unsupported class file versions now produce one IKVM0146 warning per
  input naming the Java release(s) and the supported maximum (52.0,
  Java 8); per-class details move to the IKVM0010 info diagnostic.
- IKVM0147 warns when no classes at all could be compiled from an input.
- module-info.class and META-INF/versions/ entries are no longer treated
  as classes; a Java 8 runtime never loads them.
- The runtime's UnsupportedClassVersionError uses the same wording, and
  defineClass now throws UnsupportedClassVersionError rather than
  ClassFormatError for versions IKVM.ByteCode rejects.

Fixes #127
Exceptions thrown to Java code now use HotSpot's exact text instead of the
importer's wording:

  p/A has been compiled by a more recent version of the Java Runtime (class
  file version 55.0), this version of the Java Runtime only recognizes class
  file versions up to 52.0

or, when no name was given (defineClass with a null name, and anonymous
classes, which HotSpot parses without a name):

  Unsupported class file version 55.0, this version of the Java Runtime only
  recognizes class file versions up to 52.0

The class name is in internal form, as in HotSpot. The importer keeps its own
wording for diagnostics, including loose .class files on the command line.
@CLAassistant

CLAassistant commented Oct 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

HotSpot accepts every 45.x class file, but IKVM rejected anything below 45.3
with UnsupportedClassVersionError. The only format difference before 45.3 is
the Code attribute header (u1 max_stack, u1 max_locals, u2 code_length instead
of u2, u2, u4), which IKVM.ByteCode always decodes in the modern layout, so
decode the narrower header ourselves for those versions. A Code attribute
whose contents do not add up to its length is a ClassFormatError, using
HotSpot's wording.
@wasabii
wasabii force-pushed the claude/clever-hawking-ziehrb branch from e54361d to 0ed0136 Compare October 17, 2026 21:48
System.Reflection.Metadata is imported for PEReader, which makes
BlobBuilder ambiguous with IKVM.ByteCode.Buffers.BlobBuilder (CS0104).
main moved class file parsing into IKVM.CoreLib.Linking and replaced the
runtime's UnsupportedClassVersionError with
IKVM.CoreLib.Linking.UnsupportedClassVersionException, which map.xml
translates to java.lang.UnsupportedClassVersionError.

The supported version range, the Java release names and the message
formatting from this branch now live on UnsupportedClassVersionException.
It carries the version and, where known, the class name, so the message
seen by Java code still matches HotSpot. The narrower pre-45.3 Code
attribute decoding moves to the CoreLib Method, and the helper tests move
to IKVM.CoreLib.Tests.
@wasabii
wasabii force-pushed the claude/clever-hawking-ziehrb branch from 594ad4c to 20e691a Compare October 21, 2026 23:07
@wasabii
wasabii force-pushed the claude/clever-hawking-ziehrb branch 2 times, most recently from 772f06c to 9930fcb Compare October 22, 2026 07:36
…alTest on Windows

actions/cache evaluates its key expression again in the post step that saves
the cache. By then the workspace holds the OpenJDK submodule and every build
output, and hashFiles('**/*.csproj', ...) over all of it regularly exceeds its
120 second limit, failing the Build IKVM job after a successful build. Hash the
tracked project files with git ls-files in a separate step instead, and use its
output as the key.

ButtonGroupLayoutTraversalTest was excluded on Linux for failing intermittently
with a component not reachable in the forward focus cycle. It now fails the
same way on windows-x64, on pull requests that don't touch AWT.
wasabii added a commit that referenced this pull request Oct 22, 2026
It was already excluded on macOS. On #797 it failed on win-x64 with
"Applet thread threw exception: java.lang.RuntimeException: Test failed!"
in both the net472 and net8.0 partitions, on a change that doesn't touch
AWT. The .html applet test and its .java class stay in step, as the other
entries do.
It was already excluded on macOS. On #797 it failed on win-x64 with
"Applet thread threw exception: java.lang.RuntimeException: Test failed!"
in both the net472 and net8.0 partitions, on a change that doesn't touch
AWT. The .html applet test and its .java class stay in step, as the other
entries do.
The Archive Test Results step failed on win-x64 after every test had passed.
The runner's tar writes ustar headers, converting each file name to the
system code page, and stopped at the first langtools tools/javac/unicode
entry whose name has a character outside the Basic Multilingual Plane (the
SupplementaryJavaID tests), exiting 1 without printing an error. pax stores
file names as UTF-8, so the archive keeps every file and the step still fails
when tar does.
This reverts commit 155314c.

The pax format did not fix the Archive Test Results failure on win-x64. The
default format archived the SupplementaryJavaID6 class files fine in other
runs, and tar still exited 1 at the same point with --format=pax, so the file
name encoding was not the cause.
tar has been exiting 1 on win-x64 after every test passed, without printing
an error. When that step fails on Windows, list the processes still running
from the work directory and the test results files whose names are not
printable ASCII, with their UTF-16 code units, then run tar again with its
error output shown. The step doesn't change the job's result.
wasabii added a commit that referenced this pull request Oct 23, 2026
…Windows

Both were already excluded on other platforms and have now each failed twice
on win-x64, in OpenJDK partition 8 (net8.0) on #805 and #797, on changes that
don't touch AWT or accessibility:

- JGlassPaneInternalFrameOverlapping: "The HW component did not pass pixel
  color check and is not drawn correctly". It was excluded on linux-all and
  macosx-all, so it is now generic-all.
- SlowPanelIteration: "Too slow operation". It was excluded on macosx-all,
  so it is now macosx-all,windows-all.
wasabii added a commit that referenced this pull request Oct 23, 2026
…Windows

Both were already excluded on other platforms and have now each failed twice
on win-x64, in OpenJDK partition 8 (net8.0) on #805 and #797, on changes that
don't touch AWT or accessibility:

- JGlassPaneInternalFrameOverlapping: "The HW component did not pass pixel
  color check and is not drawn correctly". It was excluded on linux-all and
  macosx-all, so it is now generic-all.
- SlowPanelIteration: "Too slow operation". It was excluded on macosx-all,
  so it is now macosx-all,windows-all.
…Windows

Both were already excluded on other platforms and have now each failed twice
on win-x64, in OpenJDK partition 8 (net8.0) on #805 and #797, on changes that
don't touch AWT or accessibility:

- JGlassPaneInternalFrameOverlapping: "The HW component did not pass pixel
  color check and is not drawn correctly". It was excluded on linux-all and
  macosx-all, so it is now generic-all.
- SlowPanelIteration: "Too slow operation". It was excluded on macosx-all,
  so it is now macosx-all,windows-all.
@wasabii
wasabii merged commit f30cd7b into main Oct 31, 2026
190 of 195 checks passed
@wasabii
wasabii deleted the claude/clever-hawking-ziehrb branch October 31, 2026 21:55
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 this pull request may close these issues.

Improve error message when class file format (version) is not supported (e.g. higher than 52)

2 participants