roscopeco/jasm

Parser issues with names and string escape

jumanji144 opened this issue · 3 comments

The nature of this issue is that there are alot of open problems about dealing with technially jvm valid input but invalid input regarding to antlr or jasm

public class java/lang/Example {
    public test()V {
        getstatic 1.0 I
    }
}

Results in: test.j : Cannot invoke "org.antlr.v4.runtime.tree.RuleNode.getChildCount()" because "node" is null

This should work because 1.0 is a valid path descriptor

Any class, extends, implements, method or field declaration fails when the access modifiers are used as names, but they should because they are valid jvm names
Example

public class public
extends private
implements final, static, private {

}

Is technically valid by the JVM but jasm errors with: test.j : Cannot invoke "org.antlr.v4.runtime.tree.TerminalNode.getText()" because the return value of "com.roscopeco.jasm.antlr.JasmParser$ClassnameContext.QNAME()" is null

It is impossible to name lables, variables, methods after any instruction and it will fail with: test.j : Cannot read field "inputLocals" because "dstFrame" is null in the goto case.

Example:

public class java/lang/Example {
	
    public test()V {
        goto ldc
		
		ldc:
			return
    }
}

It is also impossible for invokex descriptors to contain any keywords

Example:

public class java/lang/Example {
	
    public test()V {
        invokevirtual ldc/private.final(goto)V
    }
}

Also string escape is not working on example:

public class java/lang/Example {
	
    public test()V {
        ldc "\"\\\\\\\""
    }
	
}

Which should just result in the string '"\"' but instead errors with: test.j : Errors: test.j:[4:22]: extraneous input '""'

Thanks for the report, all good points :)

To check my understanding, what are you expecting from:

getstatic 1.0 I

? I assume you mean a field named "0" on a class named "1"?

yes

Fixed with new literal names syntax.

Your point about string escapes isn't quite correct at the moment - JASM does not support backslash escapes. The way to escape quotes in a string is with "". However, going forward I'd like to add more robust escaping for other special characters, so I raised #37 to cover that.

Thanks again for reporting!