Add explicit return type checks for extensible enums, fix exc

This commit is contained in:
tterrag 2019-04-25 19:51:20 -04:00
parent cab1b9716c
commit 616416569b
2 changed files with 14 additions and 3 deletions

View file

@ -83,9 +83,9 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
return false;
}
//Static methods named "create", with first argument as a string, and returning this type
//Static methods named "create" with first argument as a string
List<MethodNode> candidates = classNode.methods.stream()
.filter(m -> ((m.access & Opcodes.ACC_STATIC) != 0) && m.name.equals("create") && Type.getReturnType(m.desc).equals(classType))
.filter(m -> ((m.access & Opcodes.ACC_STATIC) != 0) && m.name.equals("create"))
.collect(Collectors.toList());
if (candidates.isEmpty()) {
@ -103,6 +103,17 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
}));
throw new IllegalStateException("Enum has create method without String as first parameter: " + mtd.name + mtd.desc);
}
Type ret = Type.getReturnType(mtd.desc);
if (!ret.equals(classType)) {
LOGGER.fatal(()->new AdvancedLogMessageAdapter(sb-> {
sb.append("Enum has create method with incorrect return type:\n");
sb.append(" Enum: " + classType.getDescriptor()).append("\n");
sb.append(" Target: ").append(mtd.name + mtd.desc).append("\n");
sb.append(" Found: ").append(ret.getClassName()).append(", Expected: ").append(classType.getClassName());
}));
throw new IllegalStateException("Enum has create method with incorrect return type: " + mtd.name + mtd.desc);
}
Type[] ctrArgs = new Type[args.length + 1];
ctrArgs[0] = STRING;

View file

@ -28,7 +28,7 @@ net/minecraft/entity/player/EntityPlayer.getDigSpeed(Lnet/minecraft/block/state/
net/minecraft/entity/player/EntityPlayerMP.changeDimension(Lnet/minecraft/world/dimension/DimensionType;Lnet/minecraftforge/common/util/ITeleporter;)Lnet/minecraft/entity/Entity;=|p_212321_1_,teleporter
net/minecraft/item/ArmorMaterial.create(Ljava/lang/String;Ljava/lang/String;I[IILnet/minecraft/util/SoundEvent;FLjava/util/function/Supplier;)Lnet/minecraft/item/ArmorMaterial;=|name,p_i48533_3_,p_i48533_4_,p_i48533_5_,p_i48533_6_,p_i48533_7_,p_i48533_8_,p_i48533_9_
net/minecraft/item/EnumRarity.create(Ljava/lang/String;Lnet/minecraft/util/text/TextFormatting;)Lnet/minecraft/tileentity/BannerPattern;=|enumName,p_i48837_3_
net/minecraft/item/EnumRarity.create(Ljava/lang/String;Lnet/minecraft/util/text/TextFormatting;)Lnet/minecraft/item/EnumRarity;=|enumName,p_i48837_3_
net/minecraft/item/ItemStack.<init>(Lnet/minecraft/util/IItemProvider;ILnet/minecraft/nbt/NBTTagCompound;)V=|p_i48204_1_,p_i48204_2_,capNBT
net/minecraft/network/PacketBuffer.writeItemStack(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/network/PacketBuffer;=|p_150788_1_,limitedTag