[TIMOB-23198] Hyperloop: Android can't access fields with primitive array types
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-04-14T14:57:18.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.4.0 |
Components | Hyperloop |
Labels | android, hyperloop |
Reporter | Brian García |
Assignee | Christopher Williams |
Created | 2016-04-12T15:25:30.000+0000 |
Updated | 2016-07-21T20:44:04.000+0000 |
Description
When trying to instantiate BluetoothGattDescriptior
var BGD = new BluetoothGattDescriptor();
the following error log appears :
[WARN] : W/System.err: java.lang.NoSuchMethodException: <init> []
[WARN] : W/System.err: at java.lang.Class.getConstructor(Class.java:531)
[WARN] : W/System.err: at java.lang.Class.getConstructor(Class.java:495)
[WARN] : W/System.err: at hyperloop.HyperloopUtil.resolveConstructor(HyperloopUtil.java:297)
[WARN] : W/System.err: at hyperloop.ClassProxy.newInstance(ClassProxy.java:80)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.handleMessage(V8Function.java:82)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145)
[WARN] : W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5951)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Native Method)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
[WARN] : W/System.err: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
[WARN] : W/System.err: at hyperloop.HyperloopUtil.convert(HyperloopUtil.java:166)
[WARN] : W/System.err: at hyperloop.ClassProxy.newInstance(ClassProxy.java:89)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.handleMessage(V8Function.java:82)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:145)
[WARN] : W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5951)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Native Method)
[WARN] : W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
[WARN] : W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
[ERROR] : TiExceptionHandler: (main) [15625,21062] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [1,21063] - In hyperloop/android.bluetooth.BluetoothGattDescriptor.js:1,69
[ERROR] : TiExceptionHandler: (main) [1,21064] - Message: Uncaught Error: length=0; index=0
[ERROR] : TiExceptionHandler: (main) [1,21065] - Source: ame?arguments[0]:android.bluetooth.BluetoothGattDescriptor["class"].newInstanc
[ERROR] : V8Exception: Exception occurred at hyperloop/android.bluetooth.BluetoothGattDescriptor.js:1: Uncaught Error: length=0; index=0
Other issue is related with BluetoothGattCharacteristic, when trying to access it's methods, instantiate or cast the following error shows up:
[ERROR] : TiExceptionHandler: (main) [12908,12908] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [1,12909] - In ti:/module.js:280,9
[ERROR] : TiExceptionHandler: (main) [0,12909] - Message: Uncaught Error: Requested module not found: [B
[ERROR] : TiExceptionHandler: (main) [1,12910] - Source: throw new Error("Requested module not found: " + request);
[ERROR] : V8Exception: Exception occurred at ti:/module.js:280: Uncaught Error: Requested module not found: [B
Hello, Can you please explain a little more. Please provide a sample test case or a sample project for us to test in our environment. Also, Please provide a complete list of steps to follow. We will let you know the result ones we test the issue in our environment. Regards, Sharif.
in any app.js with hyperloop 1.1.2:
If further information is needed the reproducible test case is more complex.
Hey [~bgarcia], did that work before? [~cwilliams] any idea what could cause this?
Hi @Hans Knoechel, with other classes it works properly. Another issue that I've detected is that when calling BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE it return undefined.
The second error message about the require failing for "[B" is the same error that caused TIMOB-23179 - we were improperly trying to wrap arrays in hyperloop proxies rather than letting the kroll bridge translate the array in a JS array. So that issue should now be fixed in master branch of the module.
So I believe that this is fixed now (likely by my recent fixes?). Here's what I tried:
That ran fine and spit out:
The fixes are available on master builds of the hyperloop.next module, I used the zip from https://jenkins.appcelerator.org/job/hyperloop-next/35/artifact/dist/hyperloop-1.1.2.zip I don't know when we plan to push out new versions of the module externally so users can also try it...
Hi Chris, Could you try the return of BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE? How can I download that build? Just to check if I can go forward on the example I want to implement. Thanks!
Ah, that still fails. Let me look.
As far as when we'll release a new version of the module, I'm talking to [~hansknoechel] about that now. For the issue around BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE - that looks to be because when we retrieve fields of a class through reflection we can get primitive arrays back - rather than the boxed types (i.e. byte[] vs Byte[]). Whereas with method reflection I think we always get boxed types - even with arrays. So I needed to add the full list of primitive array types into the "whitelist" of types not to wrap in special hyperloop proxies and allow the bridge to translate to JS. There's also some extra hoops around the act that our bridge seems to handle every primitive array type except byte[], so I'll need to special case byte[] to make it a short[] first.
OK, I've got a quick fix in a PR: https://github.com/appcelerator/hyperloop.next/pull/16
Closing ticket as fixed. Verified that I was able to access fields with primitive array types; used above sample code and tried with
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
. *However,* I did encounter aUncaught RangeError: Maximum call stack size exceeded
runtime error when you try to stringify an object instance i.e.console.log(JSON.stringify(BGD));
. Will file another ticket for this issue. Tested on: Appc CLI NPM: 4.2.7 Appc CLI Core: 5.4.0-33 Arrow: 1.8.2 SDK: 5.4.0.v20160720201924 Hyperloop: 1.2.3 Node: v4.4.7 OS: Mac OS X (10.11.5) Devices: Samsung Galaxy S5 (4.4.2), Genymotion Emulator (5.1.0)[~wluu] I guess that is not really an issue, because logging it would try to print all of its attributes etc which causes the app to run out of memory. It's not really a common use-case, but file it anyway so we can discuss it there. [~cwilliams] will know best
[~hansknoechel], Agreed. So instead, I wrote a an improvement ticket to have a meaningful error message similar to iOS: TIMOB-23672