diff --git a/acrarium/src/main/kotlin/com/faendir/acra/domain/ReportService.kt b/acrarium/src/main/kotlin/com/faendir/acra/domain/ReportService.kt index bf576796..c38de152 100644 --- a/acrarium/src/main/kotlin/com/faendir/acra/domain/ReportService.kt +++ b/acrarium/src/main/kotlin/com/faendir/acra/domain/ReportService.kt @@ -21,7 +21,6 @@ import com.faendir.acra.persistence.bug.BugRepository import com.faendir.acra.persistence.device.DeviceRepository import com.faendir.acra.persistence.report.Report import com.faendir.acra.persistence.report.ReportRepository -import com.faendir.acra.persistence.version.VersionKey import com.faendir.acra.persistence.version.VersionRepository import com.faendir.acra.settings.AcrariumConfiguration import com.faendir.acra.util.findInt @@ -30,6 +29,7 @@ import com.faendir.acra.util.toDate import org.acra.ReportField import org.intellij.lang.annotations.Language import org.jooq.JSON +import org.json.JSONException import org.json.JSONObject import org.springframework.security.access.prepost.PreAuthorize import org.springframework.stereotype.Service @@ -57,7 +57,12 @@ class ReportService( ): Report { val appId = appRepository.findId(reporterUserName) ?: throw IllegalArgumentException("No app for reporter $reporterUserName") - val json = JSONObject(content) + + val json = try { + JSONObject(content) + } catch (e: JSONException) { + throw IllegalArgumentException("Invalid JSON:\n$content", e) + } val stacktrace = json.getString(ReportField.STACK_TRACE.name) val bugIdentifier = BugIdentifier.fromStacktrace(acrariumConfiguration, appId, stacktrace) diff --git a/acrarium/src/main/kotlin/com/faendir/acra/navigation/RouteParams.kt b/acrarium/src/main/kotlin/com/faendir/acra/navigation/RouteParams.kt index 01e8611d..a7351a4b 100644 --- a/acrarium/src/main/kotlin/com/faendir/acra/navigation/RouteParams.kt +++ b/acrarium/src/main/kotlin/com/faendir/acra/navigation/RouteParams.kt @@ -1,5 +1,5 @@ /* - * (C) Copyright 2022 Lukas Morawietz (https://github.com/F43nd1r) + * (C) Copyright 2022-2023 Lukas Morawietz (https://github.com/F43nd1r) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package com.faendir.acra.navigation import com.faendir.acra.persistence.app.AppId import com.faendir.acra.persistence.bug.BugId -import com.faendir.acra.util.* +import com.faendir.acra.util.toNullable import com.vaadin.flow.component.UI import com.vaadin.flow.router.BeforeEnterEvent import com.vaadin.flow.router.BeforeEnterListener @@ -49,8 +49,9 @@ class RouteParams : UIInitListener, BeforeEnterListener { fun installationId(): String = parse(PARAM_INSTALLATION) { it } fun parse(param: String, parse: (String) -> T?): T { - return parse(cache[UI.getCurrent().uiId]?.get(param)?.toNullable() ?: throw IllegalArgumentException("Parameter $param not present")) - ?: throw IllegalArgumentException("Parse failure for parameter $param") + val id = UI.getCurrent()?.uiId ?: throw IllegalStateException("No UI present") + val value = cache[id]?.get(param)?.toNullable() ?: throw IllegalArgumentException("Parameter $param not present") + return parse(value) ?: throw IllegalArgumentException("Parse failure for parameter $param") } }