Top Description Inners Fields Constructors Methods
io.github.classgraph

pack-priv Class Classfile

extends Object
Class Inheritance
Imports
java.io.IOException, java.lang.reflect.Array, .Modifier, java.util.ArrayList, .Arrays, .Collections, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, io.github.classgraph.Scanner.ClassfileScanWorkUnit, nonapi.io.github.classgraph.concurrency.WorkQueue, nonapi.io.github.classgraph.fileslice.reader.ClassfileReader, nonapi.io.github.classgraph.scanspec.ScanSpec, nonapi.io.github.classgraph.types.ParseException, nonapi.io.github.classgraph.utils.CollectionUtils, .JarUtils, .LogNode, .StringUtils

A classfile binary format parser. Implements its own buffering to avoid the overhead of using DataInputStream. This class should only be used by a single thread at a time, but can be re-used to scan multiple classfiles in sequence, to avoid re-allocating buffer memory.

See the class file format spec.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Classfile.ClassContainment

Class containment.

pack-priv static class
Classfile.ClassfileFormatException

Thrown when a classfile's contents are not in the correct format.

pack-priv static interface
pack-priv static interface
pack-priv static class
Classfile.SkipClassException

Thrown when a classfile needs to be skipped.

pack-priv static interface
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final Set<String>
acceptedClassNamesFound

The names of accepted classes found in the classpath while scanning paths within classpath elements.

private List<Scanner.ClassfileScanWorkUnit>
additionalWorkUnits

Any additional work units scheduled for scanning.

private AnnotationParameterValueList
annotationParamDefaultValues

Annotation default parameter values.

private AnnotationInfoList
classAnnotations

The class annotations.

private List<Classfile.ClassContainment>
classContainmentEntries

Class containment entries.

private final Resource
classfileResource

The classfile resource.

private int
classModifiers

The class modifiers.

private String
className

The name of the class.

private final Set<String>
classNamesScheduledForExtendedScanning

The names of external (non-accepted) classes scheduled for extended scanning (where scanning is extended upwards to superclasses, interfaces and annotations).

private final ClasspathElement
classpathElement

The classpath element that contains this classfile.

private final List<ClasspathElement>
classpathOrder

The classpath order.

private List<Classfile.ClassTypeAnnotationDecorator>
classTypeAnnotationDecorators

The type annotation decorators for the ClassTypeSignature instance.

private int
cpCount

The number of constant pool entries plus one.

private int[]
entryOffset

The byte offset for the beginning of each entry in the constant pool.

private int[]
entryTag

The tag (type) for each entry in the constant pool.

private FieldInfoList
fieldInfoList

The field info list.

private String
fullyQualifiedDefiningMethodName

The fully qualified name of the defining method.

private List<String>
implementedInterfaces

The implemented interfaces.

private int[]
indirectStringRefs

The indirection index for String/Class entries in the constant pool.

private boolean
isAnnotation

Whether this class is an annotation.

private final boolean
isExternalClass

Whether this is an external class.

private boolean
isInterface

Whether this class is an interface.

private boolean
isRecord

Whether this class is a record.

private int
majorVersion

The major version of the classfile format.

private MethodInfoList
methodInfoList

The method info list.

private int
minorVersion

The minor version of the classfile format.

private static final AnnotationInfo[]
NO_ANNOTATIONS

An empty array for the case where there are no annotations.

private ClassfileReader
reader

The ClassfileReader for the current classfile.

private Set<String>
refdClassNames

Referenced class names.

private final String
relativePath

The relative path to the classfile (should correspond to className).

private final ScanSpec
scanSpec

The scan spec.

private String
sourceFile

The source file, such as Classfile.java

private final ConcurrentHashMap<String, String>
stringInternMap

The string intern map.

private String
superclassName

The superclass name.

private String
typeSignatureStr

The type signature.

Constructor Summary

AccessConstructor and Description
pack-priv
Classfile(final ClasspathElement
the classpath element
classpathElement
,
final List<ClasspathElement>
the classpath order
classpathOrder
,
final Set<String>
the names of accepted classes found in the classpath while scanning paths within classpath elements.
acceptedClassNamesFound
,
final Set<String>
the names of external (non-accepted) classes scheduled for extended scanning (where scanning is extended upwards to superclasses, interfaces and annotations).
classNamesScheduledForExtendedScanning
,
final String
the relative path
relativePath
,
final Resource
the classfile resource
classfileResource
,
final boolean
if this is an external class
isExternalClass
,
final ConcurrentHashMap<String, String>
the string intern map
stringInternMap
,
final WorkQueue<Scanner.ClassfileScanWorkUnit>
the work queue
workQueue
,
final ScanSpec
the scan spec
scanSpec
,
final LogNode
the log
log
)

Directly examine contents of classfile binary header to determine annotations, implemented interfaces, the super-class etc. Creates a new ClassInfo object, and adds it to classNameToClassInfoOut.

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

true, if successful
constantPoolStringEquals
(final int
the constant pool index
cpIdx
,
final String
the ASCII string to compare to
asciiStr
)

Compare a string in the constant pool with a given ASCII string, without constructing the constant pool String object.

private int

Returns:

the int
cpReadInt
(final int
the constant pool index.
cpIdx
)

Read an int from the constant pool.

private long

Returns:

the long
cpReadLong
(final int
the constant pool index.
cpIdx
)

Read a long from the constant pool.

private void
extendScanningUpwards(final LogNode
the log
log
)

Check if scanning needs to be extended upwards to an external superclass, interface or annotation.

private void
extendScanningUpwardsFromAnnotationParameterValues(final Object
the AnnotationInfo object for an annotation, or for an annotation parameter value.
annotationParamVal
,
final LogNode
the log
log
)

Check if scanning needs to be extended upwards from an annotation parameter value.

private String

Returns:

the constant pool class descriptor
getConstantPoolClassDescriptor
(final int
the constant pool index
cpIdx
)

Get a string from the constant pool representing an internal string descriptor for a class name ("Lcom/xyz/MyClass;"), and interpret it as a class name by replacing '/' with '.', and removing the leading "L" and the trailing ";".

private String

Returns:

the constant pool class name
getConstantPoolClassName
(final int
the constant pool index
cpIdx
)

Get a string from the constant pool, and interpret it as a class name by replacing '/' with '.'.

private String

Returns:

the constant pool string
getConstantPoolString
(final int
the constant pool index
cpIdx
,
final boolean
if true, replace slash with dot in the result.
replaceSlashWithDot
,
final boolean
if true, strip 'L' from the beginning and ';' from the end before returning (for class reference constants)
stripLSemicolon
)

Get a string from the constant pool, optionally replacing '/' with '.'.

private String

Returns:

the constant pool string
getConstantPoolString
(final int
the constant pool index
cpIdx
,
final int
should be 0 for CONSTANT_Utf8, CONSTANT_Class and CONSTANT_String, and for CONSTANT_NameAndType_info, fetches the name for value 0, or the type descriptor for value 1.
subFieldIdx
)

Get a string from the constant pool.

private String

Returns:

the constant pool string
getConstantPoolString
(final int
the constant pool index
cpIdx
)

Get a string from the constant pool.

private byte

Returns:

the first byte of the constant pool string
getConstantPoolStringFirstByte
(final int
the constant pool index
cpIdx
)

Get the first UTF8 byte of a string in the constant pool, or '\0' if the string is null or empty.

private int

Returns:

the constant pool string offset
getConstantPoolStringOffset
(final int
the constant pool index
cpIdx
,
final int
should be 0 for CONSTANT_Utf8, CONSTANT_Class and CONSTANT_String, and for CONSTANT_NameAndType_info, fetches the name for value 0, or the type descriptor for value 1.
subFieldIdx
)

Get the byte offset within the buffer of a string from the constant pool, or 0 for a null string.

private Object

Returns:

the field constant pool value
getFieldConstantPoolValue
(final int
the tag
tag
,
final char
the first char of the field type descriptor
fieldTypeDescriptorFirstChar
,
final int
the constant pool index
cpIdx
)

Get a field constant from the constant pool.

private String

Returns:

the string
intern
(final String
the str
str
)

Intern a string.

private AnnotationInfo

Returns:

the annotation, as an AnnotationInfo object.
readAnnotation
()

Read annotation entry from classfile.

private Object

Returns:

the annotation element value
readAnnotationElementValue
()

Read annotation element value from classfile.

private void
readBasicClassInfo()

Read basic class information.

private void
readClassAttributes()

Read class attributes.

private void
readConstantPoolEntries(final LogNode
The log
log
)

Read constant pool entries.

private void
readFields()

Read the class' fields.

private void
readInterfaces()

Read the class' interfaces.

private void
readMethods()

Read the class' methods.

private List<Classfile.TypePathNode>
private void
scheduleScanningIfExternalClass(final String
the class name
className
,
final String
the relationship type
relationship
,
final LogNode
the log
log
)

Extend scanning to a superclass, interface or annotation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait