Skip to content
New issue

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

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

Already on GitHub? # to your account

Default WrapFactory doesn't properly handle the isJavaPrimitiveWrap() flag #992

Closed
p-bakker opened this issue Jul 6, 2021 · 2 comments
Closed
Labels
bug Issues considered a bug Java Interop Issues related to the interaction between Java and JavaScript Potentially Breaking Change Issues that could break backwards compatibility

Comments

@p-bakker
Copy link
Collaborator

p-bakker commented Jul 6, 2021

According to the JavaDoc on WrapFactory.isJavaPrimitiveWrap() the purpose of this falg is to expose Java primitives as native JavaScript primitives in JS land.

However, the code here first checks if !isJavaPrimitivateWrap() to return the object as is, but if isJavaPrimitivateWrap() == true continues onwards to call wrapAsJavaObject, which returns a NativeJavaObject.

So, IMHO, the isJavaPrimitiveWrap() is basically never properly used to wrap Java primitives as Native JavaScript objects.

Now, this you can fix by implementing your own WrapFactory, but I feel this is a bug that we should fix at some point. Is probably a breaking change that we should then slate for v2.0.0

Code below an example of not properly wrapping Java primitives > JavaScript primities

var x = new java.lang.String("");
var name = x.getClass().getName() // java.lang.String

name === 'java.lang.String' // false
name == 'java.lang.String' // true
typeof name // object
name.getClass() // class java.lang.String
@p-bakker p-bakker added bug Issues considered a bug Potentially Breaking Change Issues that could break backwards compatibility labels Jul 6, 2021
@p-bakker p-bakker added the Java Interop Issues related to the interaction between Java and JavaScript label Jul 6, 2021
@p-bakker
Copy link
Collaborator Author

p-bakker commented Jul 6, 2021

@p-bakker
Copy link
Collaborator Author

p-bakker commented Jul 6, 2021

I stand corrected, misinterpreted the direction of the isJavaPrimitiveWrap: needs to be set to false in order to have Java primitives exposed in JS land as native JavaScript primitives

@p-bakker p-bakker closed this as completed Jul 6, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Issues considered a bug Java Interop Issues related to the interaction between Java and JavaScript Potentially Breaking Change Issues that could break backwards compatibility
Projects
None yet
Development

No branches or pull requests

1 participant