Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jasm reporting [BUG]: <Unknown> [java.lang.NullPointerException #56

Open
alexgarzao opened this issue Mar 30, 2024 · 6 comments
Open

jasm reporting [BUG]: <Unknown> [java.lang.NullPointerException #56

alexgarzao opened this issue Mar 30, 2024 · 6 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@alexgarzao
Copy link

Hello! I'm using jasm in a "toy compiler". It's an amazing project :-)

I assembled a lot of jasm files, without any problem. But, with the example bellow, I got a "[BUG]: [java.lang.NullPointerException".

I'm using jasm 0.7.0, installed from the binary distribution.

public class if_with_integers_with_and_or {
	public static main([java/lang/String)V {
		sipush 2
		sipush 1
		if_icmple L3
		iconst_1 
		goto L4
		L3:
		iconst_0 
		L4:
		ifeq L1
		getstatic java/lang/System.out java/io/PrintStream
		ldc "true"
		invokevirtual java/io/PrintStream.print(java/lang/String)V
		getstatic java/lang/System.out java/io/PrintStream
		invokevirtual java/io/PrintStream.println()V
		goto L2
		L1:
		getstatic java/lang/System.out java/io/PrintStream
		ldc "false"
		invokevirtual java/io/PrintStream.print(java/lang/String)V
		getstatic java/lang/System.out java/io/PrintStream
		invokevirtual java/io/PrintStream.println()V
		L2:
		return
	}
}

Could someone help me?

Regards.

@cdluv
Copy link

cdluv commented Mar 30, 2024 via email

@alexgarzao
Copy link
Author

alexgarzao commented Mar 30, 2024 via email

@roscopeco
Copy link
Owner

roscopeco commented Mar 30, 2024

Hello! Glad to hear you're finding it useful, and thank you for the kind comments :)

The issue you're having is caused by the iconst lines - the correct syntax for iconst is:

iconst <num>

i.e. there are not separate instructions for the individual constants. If you remove the underscore, e.g.

iconst_1     => iconst 1
iconst_0     => iconst 0

Then it should work 🙂

So that's a workaround, however I do consider this to be a bug - it should be giving useful error messaging rather than a NullPointerException so will look at getting that fixed - thanks for the report!

@roscopeco roscopeco added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Mar 30, 2024
@alexgarzao
Copy link
Author

Using "iconst 0" and "iconst 1" works fine. Thanks :-)

Just a small question about the project. Is JASM intended to implement all JVM opcodes? In that case, I suggest taking a look at [Oracle documentation](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#:~:text=an% 20ArrayIndexOutOfBoundsException.- ,iconst_%3Ci%3E,-Operation). In this document, if I'm not mistaken, there are opcodes iconst_0 and iconst_1.

@roscopeco
Copy link
Owner

great, glad to hear the workaround fixed it for you 🥳

Indeed, those are the opcodes, and under the hood jasm assembles the code to the appropriate one based on the number - as an assembler, the syntax is designed to be consistent and convenient rather than necessarily exactly matching the underlying bytecode 🙂.

@alexgarzao
Copy link
Author

Nice. I got it. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants