Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23198] Hyperloop: Android can't access fields with primitive array types

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-04-14T14:57:18.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.4.0
ComponentsHyperloop
Labelsandroid, hyperloop
ReporterBrian García
AssigneeChristopher Williams
Created2016-04-12T15:25:30.000+0000
Updated2016-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

Comments

  1. Sharif AbuDarda 2016-04-12

    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.
  2. Brian García 2016-04-12

    in any app.js with hyperloop 1.1.2:
       var BluetoothGattDescriptor = require('android.bluetooth.BluetoothGattDescriptor');
       var BluetoothGattCharacteristic = require('android.bluetooth.BluetoothGattCharacteristic');
       var UUID = require('java.util.UUID');
       
       
       // test 1
       var BGD = new BluetoothGattDescriptor(UUID.fromString("E20A39F4-73F5-4BC4-A12F-17D1AD07A961"),0);
       
       
       
       
       // test2
       var BGD = new BluetoothGattDescriptor();
       
       //test3
       var characteristic = new BluetoothGattCharacteristic();//-> this one is not instantiated as it should, but it's enough to reproduce
       
    If further information is needed the reproducible test case is more complex.
  3. Hans Knöchel 2016-04-12

    Hey [~bgarcia], did that work before? [~cwilliams] any idea what could cause this?
  4. Brian García 2016-04-13

    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.
  5. Christopher Williams 2016-04-13

    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.
  6. Christopher Williams 2016-04-13

    So I believe that this is fixed now (likely by my recent fixes?). Here's what I tried:
       var BluetoothGattDescriptor = require('android.bluetooth.BluetoothGattDescriptor'),
       	BluetoothGattCharacteristic = require('android.bluetooth.BluetoothGattCharacteristic'),
       	UUID = require('java.util.UUID');
       
       // test 1
       var BGD = new BluetoothGattDescriptor(UUID.fromString("E20A39F4-73F5-4BC4-A12F-17D1AD07A961"), 0);
       console.log(JSON.stringify(BGD));
       console.log(BGD.getPermissions());
       console.log(BGD.getUuid().toString());
       var char = BGD.getCharacteristic();
       console.log(JSON.stringify(char));
       
    That ran fine and spit out:
       [DEBUG] Module: Loading module: hyperloop/java.util.UUID -> Resources/hyperloop/java.util.UUID.js
       [INFO]  {"$native":{"isInstanceProxy":true,"bubbleParent":true,"rect":{"height":0,"width":0,"y":0,"x":0},"children":[],"keepScreenOn":false,"size":{"height":0,"width":0,"y":0,"x":0},"isNativeProxy":true,"apiName":"android.bluetooth.BluetoothGattDescriptor"},"_hasPointer":true,"_private":{}}
       [INFO]  0
       [INFO]  e20a39f4-73f5-4bc4-a12f-17d1ad07a961
       [INFO]  null
       
    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...
  7. Brian García 2016-04-13

    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!
  8. Christopher Williams 2016-04-13

    Ah, that still fails. Let me look.
  9. Christopher Williams 2016-04-13

    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.
  10. Christopher Williams 2016-04-13

    OK, I've got a quick fix in a PR: https://github.com/appcelerator/hyperloop.next/pull/16
  11. Wilson Luu 2016-07-21

    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 a Uncaught 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)
  12. Hans Knöchel 2016-07-21

    [~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
  13. Wilson Luu 2016-07-21

    [~hansknoechel], Agreed. So instead, I wrote a an improvement ticket to have a meaningful error message similar to iOS: TIMOB-23672

JSON Source