Skip to content

Commit b801e42

Browse files
committed
Fix edge-case crash on invalid input file
1 parent 6ffeeb4 commit b801e42

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

app/src/main/kotlin/com/njlabs/showjava/activities/decompiler/DecompilerActivity.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ class DecompilerActivity : BaseActivity() {
126126
}
127127
.subscribeOn(Schedulers.io())
128128
.observeOn(AndroidSchedulers.mainThread())
129+
.onErrorReturn {
130+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
131+
resources.getDrawable(R.drawable.ic_list_generic, null)
132+
} else {
133+
resources.getDrawable(R.drawable.ic_list_generic)
134+
}
135+
}
129136
.subscribe { itemIcon.setImageDrawable(it) }
130137
)
131138

@@ -134,7 +141,12 @@ class DecompilerActivity : BaseActivity() {
134141

135142
private fun loadPackageInfoFromIntent() {
136143
if (intent.dataString.isNullOrEmpty()) {
137-
packageInfo = intent.getParcelableExtra("packageInfo")
144+
if (intent.hasExtra("packageInfo")) {
145+
packageInfo = intent.getParcelableExtra("packageInfo")
146+
} else {
147+
Toast.makeText(context, R.string.errorLoadingInputFile, Toast.LENGTH_SHORT).show()
148+
finish()
149+
}
138150
} else {
139151
val info = PackageInfo.fromFile(
140152
context,

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@
172172
<string name="useCustomFontSummary">Choose between lato or system default font</string>
173173
<string name="userInterface">User interface</string>
174174
<string name="instanceId">(ID: <xliff:g example="abc134_GTF" id="instanceIdString">%1$s</xliff:g>)</string>
175-
<string name="onlyPositiveIntegersAllowed">Only positive integers are allowed.</string>
175+
<string name="onlyPositiveIntegersAllowed">Only positive integers are allowed</string>
176+
<string name="errorLoadingInputFile">Error loading input file</string>
176177
</resources>

0 commit comments

Comments
 (0)