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

ACRA.init(this) crashing when trying to convert unsent reports #551

Closed
xrubioj opened this issue Feb 22, 2017 · 8 comments
Closed

ACRA.init(this) crashing when trying to convert unsent reports #551

xrubioj opened this issue Feb 22, 2017 · 8 comments
Assignees

Comments

@xrubioj
Copy link

xrubioj commented Feb 22, 2017

I'm having an issue where my app is failing to start (repeatedly crashing) after a crash. So far, I found that the problem is during initialization, ACRA is trying to convert unsent reports to JSON, when they are already JSON. This makes the ReportConverter#legacyLoad() parser fail, and crash the whole app.

ACRA version is last stable 4.9.2.
App installation is fresh (i.e. not an app that was using an old version of ACRA and got updated to 4.9.2).

The configuration in the Application class:

@ReportsCrashes(
        httpMethod = HttpSender.Method.PUT,
        reportType = HttpSender.Type.JSON,
        formUri = Constants.ACRA_FORM_URI,
        formUriBasicAuthLogin = Constants.ACRA_FORM_URI_BASICAUTHLOGIN,
        formUriBasicAuthPassword = Constants.ACRA_FORM_URI_BASICAUTHPASSWORD,
        mode = ReportingInteractionMode.SILENT)

In the shared preferences:

$ more xxx_preferences.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <boolean name="acra.legacyAlreadyConvertedTo4.8.0" value="true" />
</map>

Notice there is no acra.legacyAlreadyConvertedToJson preference.

Stack trace (some identifiers changed for privacy):

02-22 11:13:06.527 8774-8774/? E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.XXX.XXX.XXX, PID: 8774
 java.lang.RuntimeException: Unable to create application com.XXX.xxx.XXX.application.XXXApplication: java.lang.IllegalArgumentException: No enum constant org.acra.ReportField.{"LOGCAT"
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5406)
     at android.app.ActivityThread.-wrap2(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6119)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  Caused by: java.lang.IllegalArgumentException: No enum constant org.acra.ReportField.{"LOGCAT"
     at java.lang.Enum.valueOf(Enum.java:254)
     at org.acra.legacy.ReportConverter.legacyLoad(ReportConverter.java:297)
     at org.acra.legacy.ReportConverter.convert(ReportConverter.java:77)
     at org.acra.legacy.LegacyFileHandler.updateToCurrentVersionIfNecessary(LegacyFileHandler.java:51)
     at org.acra.ACRA.init(ACRA.java:236)
     at org.acra.ACRA.init(ACRA.java:173)
     at org.acra.ACRA.init(ACRA.java:157)
     at org.acra.ACRA.init(ACRA.java:140)
     at com.XXX.xxx.XXX.application.XXXApplication.onCreate(XXXApplication.java:112)
     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
     at android.app.ActivityThread.-wrap2(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:154) 
     at android.app.ActivityThread.main(ActivityThread.java:6119) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

The file which is trying to be converted is in app_ACRA-unapproved/2017-02-21T17:16:28.598+01:00-IS_SILENT.stacktrace, and seems a well-formed JSON file, but debugging the ReportConverter#legacyLoad() I can see the following:

{"LOGCAT""02-21 17:16:28.280 D/debuglogger(13715): [DEBUG] WMAuthActionContext#executeAction(WMAuthActionContext.java:55) - executeAction - callback failure with error status: 401 
... (all logcat data omitted)
	at java.lang.Thread.run(Thread.java:761)
","PHONE_MODEL":"Nexus 5X","TOTAL_MEM_SIZE":11454181376... (continues)

I think this last part is not relevant, as is trying to parse a JSON crash report as the legacy format, which from what I understand is key=value.

Another important bit of information is, currently the files (crash reports) present in the application are as follow:

$ ls app_ACRA-*
app_ACRA-approved:

app_ACRA-unapproved:
2017-02-21T17:16:28.598+01:00-IS_SILENT.stacktrace
@xrubioj
Copy link
Author

xrubioj commented Feb 22, 2017

After some additional investigation, the problem seems to be on my side, because an application state reset removed the preferences.

With the correct preferences in place the app starts perfectly:

$ more xxx_preferences.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <boolean name="acra.legacyAlreadyConvertedTo4.8.0" value="true" />
    <boolean name="acra.legacyAlreadyConvertedToJson" value="true" />
    <int name="acra.lastVersionNr" value="14" />
</map>

So, instead of a bug, I'll suggest an improvement to handle this strange situations in a more graceful way.

@F43nd1r
Copy link
Member

F43nd1r commented Feb 22, 2017

You're right, preference reset is a situation we have to account for.

@mtotschnig
Copy link

I have stumbled over this exact same issue, and am happy that it will be fixed in 4.9.3. In my case I was also clearing all preferences and rereading them from a backup. While I was thinking about this issue, I thought, that ideally Acra would maintain its own preferences file, so that I could safely clear my own preferences, and Acra would continue to work. Is this something that already has been discussed?

@F43nd1r
Copy link
Member

F43nd1r commented Apr 6, 2017

You can assign ACRA a different preference file using the sharedPreferencesName option

@mtotschnig
Copy link

That is good to know, thank you. Is it safe to change that option from one version to the other? Is there a mechanism that migrates values from the previous file to the new one?

@F43nd1r
Copy link
Member

F43nd1r commented Apr 6, 2017

Is it safe to change that option from one version to the other?

I'd expect it to behave exactly as if the preferences were cleared, which means it is unsafe pre-4.9.3

Is there a mechanism that migrates values from the previous file to the new one?

No, how should that even work?

@mtotschnig
Copy link

I understand it is not possible without any explicit help from client like providing the old file in the configuration. Is this something that could still make sense post-4.9.3?

@F43nd1r
Copy link
Member

F43nd1r commented Apr 6, 2017

I don't think configuration migration is in the scope of the project. But you could easily roll your own solution by migrating all keys starting with acra. to the new preferences right before the init call.

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

No branches or pull requests

3 participants