Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ public static void parse(Reader wrappedReader, String originName, BiConsumer<Tar
} else if (member.equals("*()")) {
target = new Target.WildcardMethodTarget(className);
} else if (member.contains("(")) {
String name = member.substring(0, member.indexOf('('));
// For some reason old forge ATs let you use descriptors with dots instead of slashes
// We replicate this behavior here
String desc = member.substring(member.indexOf('('))
.replace('.', '/');
var openingIndex = member.indexOf('(');
String name = member.substring(0, openingIndex);
String desc = member.substring(openingIndex);
validateMethodDescriptor(desc, reader.getLineNumber());
if (!name.equals("<init>")) {
validateIdentifier(name, "method", reader.getLineNumber());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.neoforged.accesstransformer.test;

import net.neoforged.accesstransformer.parser.AtParser;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class NoLenientDescriptorsTest {
@Test
public void testParseInvalidDescriptor() throws IOException {
try (
InputStream stream = getClass().getClassLoader().getResourceAsStream("invalid_descriptor.cfg");
Reader reader = new InputStreamReader(stream)) {
assertThrows(RuntimeException.class, () -> {
AtParser.parse(reader, "invalid_descriptor.cfg", ((target, transformation) -> {}));
}, "Invalid method descriptor 'testMethod()Lnot.valid.anymore.to.avoid.Confusion;' at line 0");
}
}
}
5 changes: 5 additions & 0 deletions src/test/resources/invalid_descriptor.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public test.Test testMethod()Lnot.valid.anymore.to.avoid.Confusion;
# The old AT grammar (using antlr) allowed descriptors of this form, and when the antlr parser was replaced with a
# hand-written one, this logic was kept. However, it turns out that this causes confusion -- as with the old antlr
# system, such ATs would be parsed but then un-apply-able, whereas they could be applied with the new parser. Thus, it's
# simplest and least confusing to just disallow this lenient syntax (a syntax not really allowed anywhere else) entirely.
16 changes: 8 additions & 8 deletions src/test/resources/test_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
public net.minecraft.client.audio.SoundManager field_148622_c #sndHandler
# Block
public net.minecraft.block.Block <init>(Lnet/minecraft/block/material/Material;)V
public net.minecraft.block.Block func_149752_b(F)Lnet.minecraft.block.Block; #setResistance
public net.minecraft.block.Block func_149711_c(F)Lnet.minecraft.block.Block; #setHardness
public net.minecraft.block.Block func_149713_g(I)Lnet.minecraft.block.Block; #setLightOpacity
public net.minecraft.block.Block func_149715_a(F)Lnet.minecraft.block.Block; #setLightValue
public net.minecraft.block.Block func_149722_s()Lnet.minecraft.block.Block; #setBlockUnbreakable
public net.minecraft.block.Block func_149675_a(Z)Lnet.minecraft.block.Block; #setTickRandomly
public net.minecraft.block.Block func_149752_b(F)Lnet/minecraft/block/Block; #setResistance
public net.minecraft.block.Block func_149711_c(F)Lnet/minecraft/block/Block; #setHardness
public net.minecraft.block.Block func_149713_g(I)Lnet/minecraft/block/Block; #setLightOpacity
public net.minecraft.block.Block func_149715_a(F)Lnet/minecraft/block/Block; #setLightValue
public net.minecraft.block.Block func_149722_s()Lnet/minecraft/block/Block; #setBlockUnbreakable
public net.minecraft.block.Block func_149675_a(Z)Lnet/minecraft/block/Block; #setTickRandomly
public net.minecraft.block.Block func_180637_b(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;I)V # dropXpOnBlockBreak
# BlockFire
public net.minecraft.block.BlockFire func_176532_c(Lnet/minecraft/block/Block;)I # getFireSpreadSpeed
public net.minecraft.block.BlockFire func_176534_d(Lnet/minecraft/block/Block;)I # getFireSpreadSpeed
# Item
public net.minecraft.item.Item func_77656_e(I)Lnet.minecraft.item.Item; #setMaxDamage
public net.minecraft.item.Item func_77627_a(Z)Lnet.minecraft.item.Item; #setHasSubtypes
public net.minecraft.item.Item func_77656_e(I)Lnet/minecraft/item/Item; #setMaxDamage
public net.minecraft.item.Item func_77627_a(Z)Lnet/minecraft/item/Item; #setHasSubtypes
# EntityPlayer
public net.minecraft.entity.player.EntityPlayer func_71053_j()V #closeScreen
# EntityTrackerEntry
Expand Down