Closed emanonwzy closed 8 years ago
Hey! Android! Niiice :)
I don't see any exception in the log regarding the Lagarto
. Was it working on previous version of Android? Do you have all required jars deployed??
Yes, It's worked on 4.x and 5.x, only crashed on 6.0. Through debug, it may be crashed on UnsafeUtil.getChars(string) in LagartoParser constructor
/**
* Creates parser on a String.
*/
public LagartoParser(String string, boolean emitStrings) {
super(emitStrings);
initialize(UnsafeUtil.getChars(string));
}
Hmm... UnsafeUtil
tries to use the unsafe method, but in case of exception, it should use ordinary getChars
from a string. Would it be possible if you go step into the UnsafeUtil.getChars
during the debugging?
@igorspasic No, it can't work this way. UnsafeUtil
class won't load if sun.misc.Unsafe
is missing, so every subsequent call to methods of this class will crash.
If you want to support Unsafe
absence, you have to introduce a delegate, trap exceptions and then fallback.
If you want to handle environments that are known to not have Unsafe
, typically Android, you can detect them upfront. Have a look at io.netty.util.internal.PlatformDependent
for an example.
Ah, yes @slandelle , you mentioned PlatformDependent
before already. Got it!
@igorspasic It throw exception when invoked below
stringValueFieldOffset = unsafe.objectFieldOffset(String.class.getDeclaredField("value"));
And crashed in below
char[] value = (char[]) UNSAFE.getObject(string, STRING_VALUE_FIELD_OFFSET);
So can this be modified like this:
if (STRING_VALUE_FIELD_OFFSET == -1) {
return string.toCharArray();
}
char[] value = (char[]) UNSAFE.getObject(string, STRING_VALUE_FIELD_OFFSET);
Thank you @emanonwzy & @slandelle! Working this out:)
Ok, commit b739570d0f3ed0665704d3041899e063452399d8 should make a difference ;) Any chance @emanonwzy to test the current version in Android? I dont have any around :(
@igorspasic Thanks. I will test on my device
It worked! Thank you very much. BTW. Do you have plan to release this fix?
No worries, the snapshot release will be published to bintray until the 14th, so it's just in couple of days :) The snapshots are stable, so you may use it without any problems.
Happy coding!
Version:
3.6.6
Appearance:
Jerry object cannot be instantiated
code url
Crash log