Package net.bytebuddy
Class ClassFileVersion
- java.lang.Object
-
- net.bytebuddy.ClassFileVersion
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ClassFileVersion>
public class ClassFileVersion extends java.lang.Object implements java.lang.Comparable<ClassFileVersion>, java.io.Serializable
A wrapper object for representing a validated class file version in the format that is specified by the JVMS.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceClassFileVersion.VersionLocatorA locator for the executing VM's Java version.
-
Field Summary
Fields Modifier and Type Field Description protected static intBASE_VERSIONThe minimal class file major version number that is legal.private static ClassFileVersion[]CLASS_FILE_VERSIONSAn array of class file versions in their sorting order.static ClassFileVersionJAVA_V1The class file version of Java 1.static ClassFileVersionJAVA_V10The class file version of Java 10.static ClassFileVersionJAVA_V11The class file version of Java 11.static ClassFileVersionJAVA_V12The class file version of Java 12.static ClassFileVersionJAVA_V13The class file version of Java 13.static ClassFileVersionJAVA_V14The class file version of Java 14.static ClassFileVersionJAVA_V15The class file version of Java 15.static ClassFileVersionJAVA_V16The class file version of Java 16.static ClassFileVersionJAVA_V17The class file version of Java 17.static ClassFileVersionJAVA_V18The class file version of Java 18.static ClassFileVersionJAVA_V19The class file version of Java 19.static ClassFileVersionJAVA_V2The class file version of Java 2.static ClassFileVersionJAVA_V20The class file version of Java 20.static ClassFileVersionJAVA_V21The class file version of Java 21.static ClassFileVersionJAVA_V22The class file version of Java 22.static ClassFileVersionJAVA_V23The class file version of Java 23.static ClassFileVersionJAVA_V24The class file version of Java 24.static ClassFileVersionJAVA_V25The class file version of Java 25.static ClassFileVersionJAVA_V26The class file version of Java 26.static ClassFileVersionJAVA_V3The class file version of Java 3.static ClassFileVersionJAVA_V4The class file version of Java 4.static ClassFileVersionJAVA_V5The class file version of Java 5.static ClassFileVersionJAVA_V6The class file version of Java 6.static ClassFileVersionJAVA_V7The class file version of Java 7.static ClassFileVersionJAVA_V8The class file version of Java 8.static ClassFileVersionJAVA_V9The class file version of Java 9.private static longserialVersionUIDThe class's serial version UID.private static ClassFileVersion.VersionLocatorVERSION_LOCATORA version locator for the executing JVM.private intversionNumberThe version number that is represented by this class file version instance.
-
Constructor Summary
Constructors Modifier Constructor Description protectedClassFileVersion(int versionNumber)Creates a wrapper for a given minor-major release of the Java class file format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassFileVersionasPreviewVersion()Returns this class file version indicating a class using preview features.intcompareTo(ClassFileVersion other)private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.booleanequals(java.lang.Object other)intgetJavaVersion()Returns the Java runtime version number of this class file version.shortgetMajorVersion()Returns the major version this instance represents.intgetMinorMajorVersion()Returns the minor-major release number of this class file version.shortgetMinorVersion()Returns the minor version this instance represents.inthashCode()booleanisAtLeast(ClassFileVersion classFileVersion)Checks if this class file version is at least as new as the provided version.booleanisAtMost(ClassFileVersion classFileVersion)Checks if this class file version is at most as new as the provided version.booleanisGreaterThan(ClassFileVersion classFileVersion)Checks if this class file version is newer than the provided version.booleanisLessThan(ClassFileVersion classFileVersion)Checks if this class file version is older than the provided version.booleanisPreviewVersion()Returnstrueif this class file version indicates the use of preview features.static ClassFileVersionlatest()Returns the latest officially supported Java version when experimental support is not enabled.static ClassFileVersionof(java.lang.Class<?> type)Extracts a class' class version.static ClassFileVersionof(java.lang.Class<?> type, ClassFileLocator classFileLocator)Extracts a class' class version.static ClassFileVersionof(TypeDescription typeDescription, ClassFileLocator classFileLocator)Extracts a class' class version.static ClassFileVersionofClassFile(byte[] binaryRepresentation)Extracts a class' class version from a class file.static ClassFileVersionofJavaVersion(int javaVersion)Creates a class file version for a given major release of Java.static ClassFileVersionofJavaVersionString(java.lang.String javaVersionString)Returns the Java class file by its representation by a version string in accordance to the formats known to javac.static ClassFileVersionofMinorMajor(int versionNumber)Creates a wrapper for a given minor-major release of the Java class file format.static ClassFileVersionofThisVm()Finds the highest class file version that is compatible to the current JVM version.static ClassFileVersionofThisVm(ClassFileVersion fallback)Finds the highest class file version that is compatible to the current JVM version.java.lang.StringtoString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
The class's serial version UID.- See Also:
- Constant Field Values
-
BASE_VERSION
protected static final int BASE_VERSION
The minimal class file major version number that is legal.- See Also:
- Constant Field Values
-
JAVA_V1
public static final ClassFileVersion JAVA_V1
The class file version of Java 1.
-
JAVA_V2
public static final ClassFileVersion JAVA_V2
The class file version of Java 2.
-
JAVA_V3
public static final ClassFileVersion JAVA_V3
The class file version of Java 3.
-
JAVA_V4
public static final ClassFileVersion JAVA_V4
The class file version of Java 4.
-
JAVA_V5
public static final ClassFileVersion JAVA_V5
The class file version of Java 5.
-
JAVA_V6
public static final ClassFileVersion JAVA_V6
The class file version of Java 6.
-
JAVA_V7
public static final ClassFileVersion JAVA_V7
The class file version of Java 7.
-
JAVA_V8
public static final ClassFileVersion JAVA_V8
The class file version of Java 8.
-
JAVA_V9
public static final ClassFileVersion JAVA_V9
The class file version of Java 9.
-
JAVA_V10
public static final ClassFileVersion JAVA_V10
The class file version of Java 10.
-
JAVA_V11
public static final ClassFileVersion JAVA_V11
The class file version of Java 11.
-
JAVA_V12
public static final ClassFileVersion JAVA_V12
The class file version of Java 12.
-
JAVA_V13
public static final ClassFileVersion JAVA_V13
The class file version of Java 13.
-
JAVA_V14
public static final ClassFileVersion JAVA_V14
The class file version of Java 14.
-
JAVA_V15
public static final ClassFileVersion JAVA_V15
The class file version of Java 15.
-
JAVA_V16
public static final ClassFileVersion JAVA_V16
The class file version of Java 16.
-
JAVA_V17
public static final ClassFileVersion JAVA_V17
The class file version of Java 17.
-
JAVA_V18
public static final ClassFileVersion JAVA_V18
The class file version of Java 18.
-
JAVA_V19
public static final ClassFileVersion JAVA_V19
The class file version of Java 19.
-
JAVA_V20
public static final ClassFileVersion JAVA_V20
The class file version of Java 20.
-
JAVA_V21
public static final ClassFileVersion JAVA_V21
The class file version of Java 21.
-
JAVA_V22
public static final ClassFileVersion JAVA_V22
The class file version of Java 22.
-
JAVA_V23
public static final ClassFileVersion JAVA_V23
The class file version of Java 23.
-
JAVA_V24
public static final ClassFileVersion JAVA_V24
The class file version of Java 24.
-
JAVA_V25
public static final ClassFileVersion JAVA_V25
The class file version of Java 25.
-
JAVA_V26
public static final ClassFileVersion JAVA_V26
The class file version of Java 26.
-
CLASS_FILE_VERSIONS
private static final ClassFileVersion[] CLASS_FILE_VERSIONS
An array of class file versions in their sorting order.
-
VERSION_LOCATOR
private static final ClassFileVersion.VersionLocator VERSION_LOCATOR
A version locator for the executing JVM.
-
versionNumber
private final int versionNumber
The version number that is represented by this class file version instance.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
ofMinorMajor
public static ClassFileVersion ofMinorMajor(int versionNumber)
Creates a wrapper for a given minor-major release of the Java class file format.- Parameters:
versionNumber- The minor-major release number.- Returns:
- A representation of the version number.
-
ofJavaVersionString
public static ClassFileVersion ofJavaVersionString(java.lang.String javaVersionString)
Returns the Java class file by its representation by a version string in accordance to the formats known to javac.- Parameters:
javaVersionString- The Java version string.- Returns:
- The appropriate class file version.
-
ofJavaVersion
public static ClassFileVersion ofJavaVersion(int javaVersion)
Creates a class file version for a given major release of Java.- Parameters:
javaVersion- The Java version.- Returns:
- A wrapper for the given Java class file version.
-
latest
public static ClassFileVersion latest()
Returns the latest officially supported Java version when experimental support is not enabled.- Returns:
- The latest officially supported Java version.
-
ofThisVm
public static ClassFileVersion ofThisVm()
Finds the highest class file version that is compatible to the current JVM version. Prior to Java 9, this is achieved by parsing thejava.versionproperty which is provided bySystem.getProperty(String). If the system property is not available, anIllegalStateExceptionis thrown.- Returns:
- The currently running Java process's class file version.
-
ofThisVm
public static ClassFileVersion ofThisVm(ClassFileVersion fallback)
Finds the highest class file version that is compatible to the current JVM version. Prior to Java 9, this is achieved by parsing thejava.versionproperty which is provided bySystem.getProperty(String). If the system property is not available, thefallbackversion is returned.- Parameters:
fallback- The version to fall back to if locating a class file version is not possible.- Returns:
- The currently running Java process's class file version or the fallback if locating this version is impossible.
-
of
public static ClassFileVersion of(java.lang.Class<?> type) throws java.io.IOException
Extracts a class' class version. The class' byte code is located by querying theClassLoaderof the class.- Parameters:
type- The type for which to locate a class file version.- Returns:
- The type's class file version.
- Throws:
java.io.IOException- If an error occurs while reading the class file.
-
of
public static ClassFileVersion of(java.lang.Class<?> type, ClassFileLocator classFileLocator) throws java.io.IOException
Extracts a class' class version.- Parameters:
type- The type for which to locate a class file version.classFileLocator- The class file locator to query for a class file.- Returns:
- The type's class file version.
- Throws:
java.io.IOException- If an error occurs while reading the class file.
-
of
public static ClassFileVersion of(TypeDescription typeDescription, ClassFileLocator classFileLocator) throws java.io.IOException
Extracts a class' class version.- Parameters:
typeDescription- The type for which to locate a class file version.classFileLocator- The class file locator to query for a class file.- Returns:
- The type's class file version.
- Throws:
java.io.IOException- If an error occurs while reading the class file.
-
ofClassFile
public static ClassFileVersion ofClassFile(byte[] binaryRepresentation)
Extracts a class' class version from a class file.- Parameters:
binaryRepresentation- The class file's binary representation.- Returns:
- The supplied class file's class file version.
-
getMinorMajorVersion
public int getMinorMajorVersion()
Returns the minor-major release number of this class file version.- Returns:
- The minor-major release number of this class file version.
-
getMajorVersion
public short getMajorVersion()
Returns the major version this instance represents.- Returns:
- The major version this instance represents.
-
getMinorVersion
public short getMinorVersion()
Returns the minor version this instance represents.- Returns:
- The minor version this instance represents.
-
getJavaVersion
public int getJavaVersion()
Returns the Java runtime version number of this class file version.- Returns:
- The Java runtime version.
-
isAtLeast
public boolean isAtLeast(ClassFileVersion classFileVersion)
Checks if this class file version is at least as new as the provided version.- Parameters:
classFileVersion- The version to check against.- Returns:
trueif this version is at least of the given version.
-
isGreaterThan
public boolean isGreaterThan(ClassFileVersion classFileVersion)
Checks if this class file version is newer than the provided version.- Parameters:
classFileVersion- The version to check against.- Returns:
trueif this version is newer than the provided version.
-
isAtMost
public boolean isAtMost(ClassFileVersion classFileVersion)
Checks if this class file version is at most as new as the provided version.- Parameters:
classFileVersion- The version to check against.- Returns:
trueif this version is as most as new as the provided version.
-
isLessThan
public boolean isLessThan(ClassFileVersion classFileVersion)
Checks if this class file version is older than the provided version.- Parameters:
classFileVersion- The version to check against.- Returns:
trueif this version is older than the provided version.
-
asPreviewVersion
public ClassFileVersion asPreviewVersion()
Returns this class file version indicating a class using preview features.- Returns:
- This class file version but indicating the use of preview features.
-
isPreviewVersion
public boolean isPreviewVersion()
Returnstrueif this class file version indicates the use of preview features.- Returns:
trueif this class file version indicates the use of preview features.
-
compareTo
public int compareTo(ClassFileVersion other)
- Specified by:
compareToin interfacejava.lang.Comparable<ClassFileVersion>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(@MaybeNull java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-