Skip to content


8311172: Classfile.PREVIEW_MINOR_VERSION doesn't match that read from…
Browse files Browse the repository at this point in the history
… class files

Reviewed-by: asotona
  • Loading branch information
liach authored and asotona committed Jul 17, 2023
1 parent afcf8e4 commit 3fb9d11
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,12 @@ default byte[] transform(ClassModel model, ClassDesc newClassName, ClassTransfor
int JAVA_21_VERSION = 65;
int JAVA_22_VERSION = 66;

* A minor version number indicating a class uses preview features
* of a Java SE version since 12, for major versions {@value
* #JAVA_12_VERSION} and above.

static int latestMajorVersion() {
return JAVA_22_VERSION;
Expand Down
59 changes: 59 additions & 0 deletions test/jdk/jdk/classfile/
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit if you need additional information or have any
* questions.
import jdk.internal.classfile.Classfile;
import org.junit.jupiter.api.Test;

import java.lang.constant.ClassDesc;

import static java.lang.constant.ConstantDescs.*;
import static jdk.internal.classfile.Classfile.*;
import static org.junit.jupiter.api.Assertions.*;

* @test
* @bug 8311172
* @run junit PreviewMinorVersionTest
* @summary Ensures Classfile.PREVIEW_MINOR_VERSION equals that of classes with
* preview minor version from ClassModel::minorVersion
public class PreviewMinorVersionTest {

public void testMinorVersionMatches() {
// compile a class with --enable-preview
// uses Record feature to trigger forcePreview
var cf = Classfile.of();
var cd = ClassDesc.of("Test");
var bytes =, cb -> cb
// old preview minor version,
// with all bits set to 1
.withVersion(JAVA_17_VERSION, -1)

var cm = Classfile.of().parse(bytes);
assertEquals(Classfile.PREVIEW_MINOR_VERSION, cm.minorVersion());

1 comment on commit 3fb9d11

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.