< prev index next > src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java
Print this page
/*
! * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
/*
! * Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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
private final byte[] buffer;
private final int metadataStart;
private final int classfileLength;
private final Function<Utf8Entry, AttributeMapper<?>> attributeMapper;
+ private final int version;
private final int flags;
private final int thisClassPos;
private ClassEntry thisClass;
private Optional<ClassEntry> superclass;
private final int constantPoolCount;
this.context = context;
this.attributeMapper = this.context.attributeMapper();
if (classfileLength < 4 || readInt(0) != 0xCAFEBABE) {
throw new IllegalArgumentException("Bad magic number");
}
! if (readU2(6) > ClassFile.latestMajorVersion()) {
! throw new IllegalArgumentException("Unsupported class file version: " + readU2(6));
}
int constantPoolCount = readU2(8);
int[] cpOffset = new int[constantPoolCount];
int p = CP_ITEM_START;
for (int i = 1; i < cpOffset.length; ++i) {
cpOffset[i] = p;
this.context = context;
this.attributeMapper = this.context.attributeMapper();
if (classfileLength < 4 || readInt(0) != 0xCAFEBABE) {
throw new IllegalArgumentException("Bad magic number");
}
! int version = readInt(4);
! if ((version & 0xFFFF) > ClassFile.latestMajorVersion()) {
+ throw new IllegalArgumentException("Unsupported class file version: " + version);
}
+ this.version = version;
int constantPoolCount = readU2(8);
int[] cpOffset = new int[constantPoolCount];
int p = CP_ITEM_START;
for (int i = 1; i < cpOffset.length; ++i) {
cpOffset[i] = p;
public int thisClassPos() {
return thisClassPos;
}
+ public int classFileVersion() {
+ return version;
+ }
+
@Override
public int classfileLength() {
return classfileLength;
}
< prev index next >