nhachicha / SnappyDB

A key-value database for Android
1.78k stars 220 forks source link

Could not find class 'sun.nio.ch.DirectBuffer' #8

Open huchunyu opened 10 years ago

huchunyu commented 10 years ago

I got the following though the snappydb still works. Do I need to worry about this?

05-28 12:01:35.836 1015-1015/com.hello.test.app E/dalvikvm﹕ Could not find class 'sun.nio.ch.DirectBuffer', referenced from method com.esotericsoftware.kryo.util.UnsafeUtil.releaseBuffer 05-28 12:01:35.836 1015-1015/com.hello.test.app W/dalvikvm﹕ VFY: unable to resolve check-cast 2143 (Lsun/nio/ch/DirectBuffer;) in Lcom/esotericsoftware/kryo/util/UnsafeUtil; 05-28 12:01:35.836 1015-1015/com.hello.test.app D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x0008 05-28 12:01:35.846 1015-1015/com.hello.test.app I/dalvikvm﹕ Could not find method sun.misc.Unsafe.addressSize, referenced from method com.esotericsoftware.kryo.serializers.FieldSerializerUnsafeUtil.fieldSizeOf 05-28 12:01:35.846 1015-1015/com.hello.test.app W/dalvikvm﹕ VFY: unable to resolve virtual method 15175: Lsun/misc/Unsafe;.addressSize ()I 05-28 12:01:35.846 1015-1015/com.hello.test.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x002d

nhachicha commented 10 years ago

Hi huchunyu,

this is Kryo crashing ... is this happening during Serialization/Desirialization (ie when putting/getting value)?

this is interesting since Kryo is not suppose to use Unsafe mode on Android ....

is it possible to share the whole StackTrace (especially the part "Unable to create serializer" if it's available) or could you share this part of code?

Cheers,

huchunyu commented 10 years ago

It's happening in putting value.

//Sample code in main activity class

try { // Debug.startMethodTracing(); db.put("Jack", new UserAuth("Jack","123456789"); // From here, I see those annoying warnings, but the app is still running. // Debug.stopMethodTracing();

} catch (Exception e) { e.printStackTrace(); }

// Class to be saved into snappyDB public class UserAuth implements Serializable { private String uid; private String token;

public void setToken(String token) {
    this.token = token;
}

public String getToken() {
    return token;
}

public void setUid(String uid) {
    this.uid = uid;
}

public String getUid() {
    return uid;
}

public UserAuth(String uid, String token) {
    this.uid = uid;
    this.token = token;
}

public UserAuth() {

}

}

nhachicha commented 10 years ago

I created a sample project with your example here https://www.dropbox.com/s/4x3xygfv7qp9o17/TestCrashSnappyDB.zip but I was unable to reproduce your exception...

could you pls give it a run and let me know how it goes?

ps: does it happen on a particular device or everywhere? which version of SnappyDB are you using ?

huchunyu commented 10 years ago

I'm using the version download from the link you posted. http://snappydb.com/snappydb-0.2.0.zip I've made gradle setting changes based on your example project. Now it works.

Thanks a lot for your help. I'll consider using your cool product into our product.

huchunyu commented 10 years ago

I'm saying too fast. I still see those warning messages.

02:45:15.880 3891-3891/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ Late-enabling CheckJNI 05-29 02:45:15.908 3891-3894/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ GC_CONCURRENT freed 126K, 14% free 2797K/3232K, paused 5ms+1ms, total 7ms 05-29 02:45:15.908 3891-3891/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ Trying to load lib /data/app-lib/dev.nhachicha.testcrashsnappydb.app-2/libsnappydb-native.so 0xa4e812f8 05-29 02:45:15.908 3891-3891/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ Added shared lib /data/app-lib/dev.nhachicha.testcrashsnappydb.app-2/libsnappydb-native.so 0xa4e812f8 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app E/dalvikvm﹕ Could not find class 'sun.nio.ch.DirectBuffer', referenced from method com.esotericsoftware.kryo.util.UnsafeUtil.releaseBuffer 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app W/dalvikvm﹕ VFY: unable to resolve check-cast 1394 (Lsun/nio/ch/DirectBuffer;) in Lcom/esotericsoftware/kryo/util/UnsafeUtil; 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x0008 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app I/dalvikvm﹕ Could not find method sun.misc.Unsafe.addressSize, referenced from method com.esotericsoftware.kryo.serializers.FieldSerializerUnsafeUtil.fieldSizeOf 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app W/dalvikvm﹕ VFY: unable to resolve virtual method 10897: Lsun/misc/Unsafe;.addressSize ()I 05-29 02:45:15.920 3891-3891/dev.nhachicha.testcrashsnappydb.app D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x002d 05-29 02:45:15.944 3891-3891/dev.nhachicha.testcrashsnappydb.app D/libEGL﹕ loaded /system/lib/egl/libEGL_genymotion.so 05-29 02:45:15.944 3891-3891/dev.nhachicha.testcrashsnappydb.app D/﹕ HostConnection::get() New Host Connection established 0xb871a3d0, tid 3891 05-29 02:45:15.948 3891-3891/dev.nhachicha.testcrashsnappydb.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_genymotion.so 05-29 02:45:15.948 3891-3891/dev.nhachicha.testcrashsnappydb.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_genymotion.so 05-29 02:45:15.964 3891-3891/dev.nhachicha.testcrashsnappydb.app W/EGL_genymotion﹕ eglSurfaceAttrib not implemented 05-29 02:45:15.964 3891-3891/dev.nhachicha.testcrashsnappydb.app E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from GradienCache 05-29 02:45:15.964 3891-3891/dev.nhachicha.testcrashsnappydb.app E/OpenGLRenderer﹕ Getting MAX_TEXTURE_SIZE from Caches::initConstraints() 05-29 02:45:15.964 3891-3891/dev.nhachicha.testcrashsnappydb.app D/OpenGLRenderer﹕ Enabling debug mode 0

huchunyu commented 10 years ago

BTW, I tried two types of virtual devices. one is from Genymotion and the other one is from Android itself.

rinav commented 10 years ago

I am having the same exception as mentioned in OP. I am also trying to save Serializable Object as follows

public class User implements Serializable {
    ...
}

public class UserInfo extends User {
    ...
}

// trying to save UserInfo throws exception
UserInfo user = new User();
user.setxxx("");
....

DB db = .....

db.put("USER_OBJ", user);

However saving primitives data types working gr8 without any problems

Any workaround to solve the issue untill 0.3.0 be released?

nhachicha commented 10 years ago

Hi,

Could you please send the generated APK & the project if possible so I can reproduce?

It will be useful also to indicate in which devices/Android version you've been having this bug.

Cheers

rinav commented 10 years ago

@nhachicha OK I’ll post a Test Project link so that you may try to find the culprit. I'll do it after I reach home.

Thanks

rinav commented 10 years ago

@nhachicha as per your request please find the github repo with test project

I have tested on Galaxy Note1(KK-4.4), Galaxy S2(JB-4.1.2), Micromax(ICS-4.0.4) and few other devices. Mostly all are running ICS+ I also tried to simply drop the jar instead of using native-gradle plugin

https://github.com/riinav/SnappDBTest

Hope it helps

nhachicha commented 10 years ago

Hey @riinav thx for the test project

I was indeed able to reproduce the message, but it's just a warning not a crash AFAIK. I was also able to save & get back User & UserInfo objects (despite the dalvikvm warning/error)

@huchunyu already reported this StackTrace without an app crashing ... can you confirm pls?

Cheers

rinav commented 10 years ago

@nhachicha Yes, you are right, it saves and gets back the Serialized Object. It does the Job. Do I need to worry about those warnings in any particular scenario, which I should take care? I was unable to test it with ART enabled.

nhachicha commented 10 years ago

Don't worry about this now (as long as it doesn't crash your VM) I tested it with ART yesterday on a GNexus with KK, no problem so far.

I'll keep this issue open though to investigate this warning later.

Cheers

thedumbtechguy commented 9 years ago

The thread was a bit hard to follow, but even though I am facing this issue, it seems to work perfectly for me. All my data is saved and retrieved same as @riinav

eanderso commented 9 years ago

I just had the same issue. I solved this by removing the final modifier. I was passing the POJO to be saved to a method that had the incoming variable as final - then passed this to a service which stores the value in the DB.

eg: onClickListener()... { saveData(dataPOJO); }

private boolean saveData(final DataPojo dataPOJO) { try ... snappyDBservice.putItem(dataPOJO.getKeyString(), dataPOJO); catch... }

daveztong commented 9 years ago

@eanderso Thanks. Remove the final modifier did work. I got some weird characters like 0x1 when using the final modifier.

lukeduca commented 8 years ago

I am having the same problem..

"Could not find class 'sun.nio.ch.DirectBuffer', referenced from method com.esotericsoftware.kryo.util.UnsafeUtil.releaseBuffer"

I have the following class:

public class AirportData implements Serializable {

private String country;
private String state;
private String city;
private String airportCode;
private String airportName;
private String latitude;
private String longitude;

public AirportData(String country, String state, String city, String airportName, String latitude, String longitude) {
    this.country = country;
    this.state = state;
    this.city = city;
    this.airportName = airportName;
    this.latitude = latitude;
    this.longitude = longitude;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getAirportCode() {
    return airportCode;
}

public void setAirportCode(String airportCode) {
    this.airportCode = airportCode;
}

public String getAirportName() {
    return airportName;
}

public void setAirportName(String airportName) {
    this.airportName = airportName;
}

public String getLatitude() {
    return latitude;
}

public void setLatitude(String latitude) {
    this.latitude = latitude;
}

public String getLongitude() {
    return longitude;
}

public void setLongitude(String longitude) {
    this.longitude = longitude;
}

}


Now in the main activity, I have the following: Inserting an new object of type AirportData:

AirportData a = new AirportData("USA", "AA", "Middletown", "Middletown Airport", "2453244", "-23555677"); try { snappyDB2.put("flight1", a); } catch (SnappydbException e) { e.printStackTrace(); }

try { AirportData ad = snappyDB2.getObject("flight1", AirportData.class);

    } catch (SnappydbException e) {
        e.printStackTrace();
    }

How can I solve this issue please? Thanks in advance..