-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Cannot resolve method/constructor signatures when null is passed #90
Comments
Possible problems while working with null parameter on the javascript side, having the set up described in the issue: 1. var a = new SomeClass(); //returns Object
2.
3. if(a == null) {
4. c.method1(a);
5. }
6.
7.
8. var b = new JavaNullClass();
9.
10. if(b == null) {
11. c.method1(b)
12. } What might happen: (case 2) So in conclusion: |
Suppose we have the following Java code public class Util {
public String getDataFileName() {
...
}
}
public class SomeClass {
public byte[] getData(String dataFileName) {
...
}
public byte[] getData(File dataFile) {
...
}
...
} and the following JavaScript code var name = util.getDataFileName();
var data = someClass.getData(name); Currently in the scenario when both I think we need both approaches suggested above or something else. Using var name = util.getDataFileName();
var data = someClass.getData(checkForNull(java.lang.String, name)); However this option does not guide the developer when to use it. My guess is that the need for method resolution will be relatively small and this or similar approach will be well accepted. This approach doesn't exclude the possibility of subtle bugs though. |
The syntax for passing null of a specific type is as has been suggested out by @slavchev var c = new Class1();
c.method1(java.lang.Object.null); // method1(Object o)
c.method1(java.lang.String.null); // method1(Strnig s) Regarding nulls returned from Java methods - developers will need to check for null and specify the type they wish to use in a follow up function like so. var result = javaClass.methodThatReturnsSomeNull();
var myNull;
if(!result)
myNull = com.a.Some.null; |
Please note that with the recent fix there is a breaking change. Consider the following scenario: Updated: That is no longer supported, and if you wish to invoke the same constructor with a primitive, you will need to make sure that you create an object wrapper. |
This comment was marked as abuse.
This comment was marked as abuse.
@NathanaelA Java objects used to have their constructors resolved, and be instantiated in Java. Before creating an instance and after finding the most adequate constructor, we used to do argument conversion - matching each argument against what the constructor expected , very similar to the one we had in C++, but instead in Java. The changes only affect object creation and should not require that you change the way method invocation has worked so far. I've updated my original comment to reflect on that. |
The following method cannot be resolved from JavaScript when called with
null
argument.Suggestion: provide
null
function, e.g.javanull
. For example:Another option is to attach
null
property to the class object. For exampleAny other suggestions are welcome.
The text was updated successfully, but these errors were encountered: