Skip to content

Commit 5bf5ac2

Browse files
committed
Allow Kotlin class names with parentheses in them (#645)
1 parent f8edf1b commit 5bf5ac2

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

src/main/java/io/github/classgraph/Classfile.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,12 @@ private List<TypePathNode> readTypePath() throws IOException {
10551055
/**
10561056
* Read constant pool entries.
10571057
*
1058+
* @param log
1059+
* The log
10581060
* @throws IOException
10591061
* Signals that an I/O exception has occurred.
10601062
*/
1061-
private void readConstantPoolEntries() throws IOException {
1063+
private void readConstantPoolEntries(final LogNode log) throws IOException {
10621064
// Only record class dependency info if inter-class dependencies are enabled
10631065
List<Integer> classNameCpIdxs = null;
10641066
List<Integer> typeSignatureIdxs = null;
@@ -1198,21 +1200,29 @@ private void readConstantPoolEntries() throws IOException {
11981200
final String typeSigStr = getConstantPoolString(cpIdx);
11991201
if (typeSigStr != null) {
12001202
try {
1201-
if (typeSigStr.indexOf('(') >= 0 || "<init>".equals(typeSigStr)) {
1202-
// Parse the type signature
1203-
final MethodTypeSignature typeSig = MethodTypeSignature.parse(typeSigStr,
1203+
if (typeSigStr.startsWith("L") && typeSigStr.endsWith(";")) {
1204+
// Parse the class name
1205+
final TypeSignature typeSig = TypeSignature.parse(typeSigStr,
12041206
/* definingClassName = */ null);
12051207
// Extract class names from type signature
12061208
typeSig.findReferencedClassNames(refdClassNames);
1207-
} else {
1209+
} else if (typeSigStr.indexOf('(') >= 0 || "<init>".equals(typeSigStr)) {
12081210
// Parse the type signature
1209-
final TypeSignature typeSig = TypeSignature.parse(typeSigStr,
1211+
final MethodTypeSignature typeSig = MethodTypeSignature.parse(typeSigStr,
12101212
/* definingClassName = */ null);
12111213
// Extract class names from type signature
12121214
typeSig.findReferencedClassNames(refdClassNames);
1215+
} else {
1216+
if (log != null) {
1217+
log.log("Could not extract referenced class names from constant pool string: "
1218+
+ typeSigStr);
1219+
}
12131220
}
12141221
} catch (final ParseException e) {
1215-
throw new ClassfileFormatException("Could not parse type signature: " + typeSigStr, e);
1222+
if (log != null) {
1223+
log.log("Could not extract referenced class names from constant pool string: "
1224+
+ typeSigStr + " : " + e);
1225+
}
12161226
}
12171227
}
12181228
}
@@ -1947,7 +1957,7 @@ public void decorate(final ClassTypeSignature classTypeSignature) {
19471957
majorVersion = reader.readUnsignedShort();
19481958

19491959
// Read the constant pool
1950-
readConstantPoolEntries();
1960+
readConstantPoolEntries(log);
19511961

19521962
// Read basic class info (
19531963
readBasicClassInfo();

0 commit comments

Comments
 (0)