Skip to content

Commit

Permalink
Fix NPE in offsetParameterIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Apr 18, 2024
1 parent 4429a39 commit 96716c3
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,24 @@ private Patch.Result offsetParameterIndex(ClassNode classNode, MethodNode method
// Validate implicit targets for @Local parameters
if (result == Patch.Result.PASS && annotation.getAllValues().isEmpty()) {
int compatLevel = methodContext.patchContext().environment().fabricLVTCompatibility();
if (compatLevel == FabricUtil.COMPATIBILITY_0_10_0) {
List<MethodContext.LocalVariable> locals = methodContext.getTargetMethodLocals(methodContext.findDirtyInjectionTarget(), 0, compatLevel);
if (locals.stream().filter(var -> var.type() == paramType).count() > 1) {
// Mixin found more locals than required, let's try to fix this
// The old method might still get us the expected results
List<MethodContext.LocalVariable> oldCompatLocals = methodContext.getTargetMethodLocals(methodContext.findDirtyInjectionTarget(), 0, FabricUtil.COMPATIBILITY_0_9_2);
List<MethodContext.LocalVariable> sameType = oldCompatLocals.stream().filter(var -> var.type() == paramType).toList();
if (sameType.size() == 1) {
int index = sameType.get(0).index();
annotation.appendValue("index", index);
LOGGER.info(PatchInstance.MIXINPATCH, "Fixing @Local annotation target on {}.{} using index {}", classNode.name, methodNode.name, index);
return Patch.Result.APPLY;
}
if (compatLevel != FabricUtil.COMPATIBILITY_0_10_0) {
return Patch.Result.PASS;
}
MethodContext.TargetPair targetPair = methodContext.findDirtyInjectionTarget();
if (targetPair == null) {
return Patch.Result.PASS;
}
List<MethodContext.LocalVariable> locals = methodContext.getTargetMethodLocals(targetPair, 0, compatLevel);
if (locals != null && locals.stream().filter(var -> var.type() == paramType).count() > 1) {
// Mixin found more locals than required, let's try to fix this
// The old method might still get us the expected results
List<MethodContext.LocalVariable> oldCompatLocals = methodContext.getTargetMethodLocals(targetPair, 0, FabricUtil.COMPATIBILITY_0_9_2);
List<MethodContext.LocalVariable> sameType = oldCompatLocals.stream().filter(var -> var.type() == paramType).toList();
if (sameType.size() == 1) {
int index = sameType.get(0).index();
annotation.appendValue("index", index);
LOGGER.info(PatchInstance.MIXINPATCH, "Fixing @Local annotation target on {}.{} using index {}", classNode.name, methodNode.name, index);
return Patch.Result.APPLY;
}
}
}
Expand Down

0 comments on commit 96716c3

Please sign in to comment.