Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StrictMode policy violation found when doing Gson mapping from onResponse() call #90

Open
jshaikql opened this issue Nov 1, 2019 · 3 comments

Comments

@jshaikql
Copy link

jshaikql commented Nov 1, 2019

I have added the following strict mode policy checks in my application onCreate() method.

private fun setStrictMode() {
        StrictMode.setThreadPolicy(
            StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectAll()   // or .detectAll() for all detectable problems
                .penaltyLog()
                .build()
        )
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        StrictMode.setVmPolicy(
             StrictMode.VmPolicy.Builder()
                 .detectNonSdkApiUsage()
                 .detectLeakedSqlLiteObjects()
                 .detectLeakedClosableObjects()
                 .penaltyLog()
                 .build()
         )
    }
}

and found NonSdkApiUsedViolation when trying to map the results from the BootstrapApi.onResponse() callback.

2019-11-01 16:18:42.856 19210-19276/com.sample.test.ui D/StrictMode: StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe;
        at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
        at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
        at java.lang.Class.getDeclaredField(Native Method)
        at com.google.gson.internal.UnsafeAllocator.create(UnsafeAllocator.java:41)
        at com.google.gson.internal.ConstructorConstructor$14.<init>(ConstructorConstructor.java:221)
        at com.google.gson.internal.ConstructorConstructor.newUnsafeAllocator(ConstructorConstructor.java:220)
        at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:96)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:101)
        at com.google.gson.Gson.getAdapter(Gson.java:458)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
        at com.google.gson.Gson.getAdapter(Gson.java:458)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:117)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:166)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
        at com.google.gson.Gson.getAdapter(Gson.java:458)
        at com.google.gson.Gson.fromJson(Gson.java:926)
        at com.google.gson.Gson.fromJson(Gson.java:892)
        at com.google.gson.Gson.fromJson(Gson.java:841)
        at com.google.gson.Gson.fromJson(Gson.java:813)
        at io.github.btkelly.gandalf.network.BootstrapApi$1.onResponse(BootstrapApi.java:118)
        at okhttp3.RealCall$AsyncCall.run(RealCall.kt:138)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
@stkent
Copy link
Collaborator

stkent commented Nov 1, 2019

Thanks for the report!

It looks like this issue might be in Gson, which Gandalf uses: google/gson#1387

I am not sure there's much we can do until Gson patches this out :/

@btkelly
Copy link
Owner

btkelly commented Nov 2, 2019

This might actually be fixed in the latest version of GSON. I was working on the other DiskRead violation and in the process just updated all of the dependencies. In doing so I don't remember seeing this violation but I'll have to check. This could also be a time for us to switch to Moshi 🤷‍♂

@skauss
Copy link

skauss commented Sep 10, 2020

Still in latest version 2.8.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants