Skip to content

Commit

Permalink
Fix class reading on inner class attributes containing local classes
Browse files Browse the repository at this point in the history
This can happen for local classes. This hasn't mattered in practice
because they aren't part of the ABI and ijar and turbine don't include
them.

PiperOrigin-RevId: 565963078
  • Loading branch information
cushon authored and Javac Team committed Sep 16, 2023
1 parent 5fff5da commit 4854e4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions java/com/google/turbine/bytecode/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.turbine.bytecode;

import static java.util.Objects.requireNonNull;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -179,8 +178,9 @@ private List<ClassFile.InnerClass> readInnerClasses(
int innerNameIndex = reader.u2();
String innerName = innerNameIndex != 0 ? constantPool.utf8(innerNameIndex) : null;
int innerClassAccessFlags = reader.u2();
if (innerName != null && (thisClass.equals(innerClass) || thisClass.equals(outerClass))) {
requireNonNull(outerClass);
if (innerName != null
&& outerClass != null
&& (thisClass.equals(innerClass) || thisClass.equals(outerClass))) {
innerclasses.add(
new ClassFile.InnerClass(innerClass, outerClass, innerName, innerClassAccessFlags));
}
Expand Down
1 change: 1 addition & 0 deletions javatests/com/google/turbine/bytecode/ClassReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void innerClass() {
cw.visitInnerClass(
"test/Hello$Inner", "test/Hello", "Inner", Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE);
cw.visitInnerClass("test/Hello$Inner$InnerMost", "test/Hello$Inner", "InnerMost", 0);
cw.visitInnerClass("test/Hello$Local", null, "Local", 0);
byte[] bytes = cw.toByteArray();

ClassFile classFile = com.google.turbine.bytecode.ClassReader.read(null, bytes);
Expand Down

0 comments on commit 4854e4e

Please sign in to comment.