Skip to content

Commit 1838875

Browse files
committed
fix #1
1 parent 6eeddef commit 1838875

File tree

2 files changed

+10
-39
lines changed

2 files changed

+10
-39
lines changed

defensor-gradle-plugin/src/main/java/com/panda912/defensor/plugin/internal/interceptor/ArrayInterceptor.kt

+10-26
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class ArrayInterceptor : BytecodeInterceptor {
3333
Opcodes.LALOAD,
3434
Opcodes.FALOAD,
3535
Opcodes.DALOAD -> handlePrimitiveType(methodNode, insnNode)
36-
Opcodes.AALOAD,
37-
Opcodes.BALOAD -> handleByteBooleanReferenceType(methodNode, insnNode)
36+
Opcodes.BALOAD -> handleByteBooleanType(methodNode, insnNode)
3837
}
3938
}
4039
}
@@ -67,7 +66,7 @@ class ArrayInterceptor : BytecodeInterceptor {
6766
methodNode.instructions.set(insnNode, methodInsnNode)
6867
}
6968

70-
private fun handleByteBooleanReferenceType(methodNode: MethodNode, insnNode: AbstractInsnNode) {
69+
private fun handleByteBooleanType(methodNode: MethodNode, insnNode: AbstractInsnNode) {
7170
val prev = insnNode.previous
7271
if (
7372
prev?.opcode == Opcodes.ILOAD ||
@@ -103,29 +102,14 @@ class ArrayInterceptor : BytecodeInterceptor {
103102
val type = Type.getType(arrayDescriptor)
104103
val dimensions = type.dimensions
105104
if (dimensions == 1) {
106-
if (insnNode.opcode == Opcodes.AALOAD) {
107-
val methodInsnNode = MethodInsnNode(
108-
Opcodes.INVOKESTATIC,
109-
COLLECTION_DEFENSOR.toInternalName(),
110-
"get",
111-
"([Ljava/lang/Object;I)Ljava/lang/Object;",
112-
false
113-
)
114-
methodNode.instructions.set(insnNode, methodInsnNode)
115-
methodNode.instructions.insert(
116-
methodInsnNode,
117-
TypeInsnNode(Opcodes.CHECKCAST, type.elementType.internalName)
118-
)
119-
} else if (insnNode.opcode == Opcodes.BALOAD) {
120-
val methodInsnNode = MethodInsnNode(
121-
Opcodes.INVOKESTATIC,
122-
COLLECTION_DEFENSOR.toInternalName(),
123-
"get",
124-
"(${arrayDescriptor}I)${type.elementType.descriptor}",
125-
false
126-
)
127-
methodNode.instructions.set(insnNode, methodInsnNode)
128-
}
105+
val methodInsnNode = MethodInsnNode(
106+
Opcodes.INVOKESTATIC,
107+
COLLECTION_DEFENSOR.toInternalName(),
108+
"get",
109+
"(${arrayDescriptor}I)${type.elementType.descriptor}",
110+
false
111+
)
112+
methodNode.instructions.set(insnNode, methodInsnNode)
129113
}
130114
}
131115
}

defensor/src/main/java/com/panda912/defensor/internal/CollectionDefensor.java

-13
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,6 @@ public static float get(float[] arr, int i) {
118118
return 0;
119119
}
120120

121-
public static <T> T get(T[] arr, int i) {
122-
if (arr != null && i >= 0 && i < arr.length) {
123-
return arr[i];
124-
}
125-
if (arr == null) {
126-
String error = "Object[i] throw NullPointerException";
127-
CrashDefensor.onCrash(ErrorCode.NullPointerException, error, new NullPointerException(error));
128-
return null;
129-
}
130-
CrashDefensor.onCrash(ErrorCode.IndexOutOfBoundsException, "Object[i] throw IndexOutOfBoundsException", new IndexOutOfBoundsException("Object[" + i + "] length " + arr.length + " throw IndexOutOfBoundsException"));
131-
return null;
132-
}
133-
134121
////////////////////////////////////////// list //////////////////////////////////////////
135122

136123
public static <E> E get(List<E> list, int index) {

0 commit comments

Comments
 (0)