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

[jvm] fix indexOf #11942

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

barisyild
Copy link
Contributor

This commit resolves the error if the indexOf parameter is null.

Code

var value:String = "data";
trace(value.indexOf(null));

Exception

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.coder()" because "str" is null
	at java.base/java.lang.String.indexOf(String.java:2593)
	at haxe.jvm.StringExt.indexOf(/usr/local/lib/haxe/std/jvm/StringExt.hx:51)
	at haxe.root.App.main(src/App.hx:36)
	at haxe.root.App.main(src/App.hx:1)

@barisyild barisyild changed the title JVM fix indexOf [JVM] fix indexOf Jan 26, 2025
@barisyild barisyild changed the title [JVM] fix indexOf [jvm] fix indexOf Jan 26, 2025
@skial skial mentioned this pull request Jan 27, 2025
1 task
@Simn
Copy link
Member

Simn commented Jan 27, 2025

Could you add a test for this? I'm curious how other targets behave.

@flashultra
Copy link
Contributor

flashultra commented Jan 27, 2025

I tested some targets ( https://try.haxe.org/#550C781c ) and the result was:
1) JS - return -1
2) Neko - ( Uncaught exception - Invalid field access : __s )
3) Eval - ( Uncaught exception Null Access )
4) Hashlink - ( Build failure )

Compiling native java code ( https://www.programiz.com/online-compiler/2pgIxccM3YmId ) will return "java.lang.NullPointerException:"

@barisyild
Copy link
Contributor Author

I tested some targets ( https://try.haxe.org/#550C781c ) and the result was: 1) JS - return -1 2) Neko - ( Uncaught exception - Invalid field access : __s ) 3) Eval - ( Uncaught exception Null Access ) 4) Hashlink - ( Build failure )

Compiling native java code ( https://www.programiz.com/online-compiler/2pgIxccM3YmId ) will return "java.lang.NullPointerException:"

hxcpp target returns 0.
I think that's wrong, needs to fixed.

@tobil4sk
Copy link
Member

This may be something better left unspecified

@Simn
Copy link
Member

Simn commented Jan 28, 2025

This may be something better left unspecified

Given the different results on each target, I agree. I'm leaving this open as a reminder to add a note to the API docs because that seems to be missing from the specification.

@barisyild
Copy link
Contributor Author

This may be something better left unspecified

Given the different results on each target, I agree. I'm leaving this open as a reminder to add a note to the API docs because that seems to be missing from the specification.

I think this is a controversial issue and I think it should be discussed.

Haxe is very similar to JavaScript and I think it makes sense to return -1 on every target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants