Android only - Returning a TokenDetails with 'issued' and 'expires' values in epoch milliseconds throws java error #356
Labels
bug
Something isn't working. It's clear that this does need to be fixed.
Setup:
Configuration:
Ably with token authentication
{{authCallback}} property in {{ClientOptions}} pointing to a function that returns a {{TokenDetails}} object. As per documentation the object contains {{issued}} and {{expires}} properties set to an epoch timestamp in milliseconds (along the rest of the properties), for clarification, the following code works flawlessly on iOS, and its equivalent in the Javascript SDK also works correctly.
Code:
{code:dart}
import 'package:ably_flutter/ably_flutter.dart' as Ably;
String _clientId = '';
Future<Ably.TokenDetails> _getTokenDetails(Ably.TokenParams params) async {
final result = await MyAPIController.getAblyAuthTokenFor(_clientId);
}
void initializeAbly(String clientId) {
_clientId = clientId;
}
{code}
Error::
{code}
E/MethodChannel#io.ably.flutter.plugin( 3539): Failed to handle method call result
E/MethodChannel#io.ably.flutter.plugin( 3539): java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec.lambda$decodeTokenDetails$32(AblyMessageCodec.java:354)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.-$$Lambda$AblyMessageCodec$EZVHcAHH13F6P7lENmPZqTXnZg8.accept(Unknown Source:2)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec.readValueFromJson(AblyMessageCodec.java:160)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec.decodeTokenDetails(AblyMessageCodec.java:354)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec.access$2300(AblyMessageCodec.java:47)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec$1.lambda$new$5(AblyMessageCodec.java:102)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.-$$Lambda$AblyMessageCodec$1$DqnBUFL6jWi43rRYX8P4My0ezrE.decode(Unknown Source:2)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec$CodecPair.decode(AblyMessageCodec.java:80)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.ably.flutter.plugin.AblyMessageCodec.readValueOfType(AblyMessageCodec.java:152)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:333)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.flutter.plugin.common.StandardMethodCodec.decodeEnvelope(StandardMethodCodec.java:107)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.flutter.plugin.common.MethodChannel$IncomingResultHandler.reply(MethodChannel.java:239)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.flutter.embedding.engine.dart.DartMessenger.handlePlatformMessageResponse(DartMessenger.java:376)
E/MethodChannel#io.ably.flutter.plugin( 3539): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessageResponse(FlutterJNI.java:993)
E/MethodChannel#io.ably.flutter.plugin( 3539): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#io.ably.flutter.plugin( 3539): at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#io.ably.flutter.plugin( 3539): at android.os.Looper.loopOnce(Looper.java:161)
E/MethodChannel#io.ably.flutter.plugin( 3539): at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#io.ably.flutter.plugin( 3539): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/MethodChannel#io.ably.flutter.plugin( 3539): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#io.ably.flutter.plugin( 3539): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#io.ably.flutter.plugin( 3539): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
{code}
It seems Java is trying to cast assign a {{long}} value as in {{int}} in the following function (lines 354 and 355):
ably-flutter/android/src/main/java/io/ably/flutter/plugin/AblyMessageCodec.java
Lines 350 to 357 in 4da3baa
In my dart code, when I truncate the the values in {{issued}} and {{expires}} to be epoch in seconds instead of milliseconds the error goes away and ably connects successfully to the server. The token is renewed at the correct time as well.
Thanks
The text was updated successfully, but these errors were encountered: