Skip to content

Commit 83ad735

Browse files
Fix NPE in version check
One of our users has an axon dependency version that does not follow semantic versioning. This causes the plugin to crash. We will now ignore malformed versions for Axon dependencies, and errors will now be caught
1 parent 91a41ab commit 83ad735

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Axon Framework plugin Changelog
44

5+
## [0.9.4]
6+
- Fix NPE in version check when using a malformed version string for an Axon dependency
7+
58
## [0.9.3]
69
- Remove build-until from plugin.xml, as we generally stay compatible with IDEA
710

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Basic plugin information
1919
pluginGroup=io.axoniq.ide.intellij
2020
pluginName=Axon Framework
21-
pluginVersion=0.9.3
21+
pluginVersion=0.9.4
2222
axonVersion=4.10.1
2323
javaVersion = 17
2424

src/main/kotlin/org/axonframework/intellij/ide/plugin/actions/ReportFeedbackAction.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.axonframework.intellij.ide.plugin.actions
1818

19+
import com.intellij.openapi.actionSystem.ActionUpdateThread
1920
import com.intellij.openapi.actionSystem.AnAction
2021
import com.intellij.openapi.actionSystem.AnActionEvent
2122
import com.intellij.openapi.application.ApplicationManager
@@ -47,4 +48,8 @@ class ReportFeedbackAction : AnAction(AxonIcons.Axon) {
4748
service.reportFeedback(e.project, feedback)
4849
}
4950
}
51+
52+
override fun getActionUpdateThread(): ActionUpdateThread {
53+
return ActionUpdateThread.BGT
54+
}
5055
}

src/main/kotlin/org/axonframework/intellij/ide/plugin/usage/AxonVersionService.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ class AxonVersionService(val project: Project) {
135135
.productionOnly()
136136
.classes()
137137
.roots
138-
.filter { it.presentableName.contains("axon") }
139138
.flatMap { root ->
140139
val jarFile = VfsUtilCore.virtualToIoFile(root)
141140
if (jarFile.extension == "jar") {
@@ -156,24 +155,29 @@ class AxonVersionService(val project: Project) {
156155
}
157156

158157
private fun extractVersion(properties: Properties): AxonDependencyVersion? {
159-
val groupId = properties.getProperty("groupId")
160-
val artifactId = properties.getProperty("artifactId")
161-
val version = properties.getProperty("version")
162-
if(groupId.isNullOrEmpty() || artifactId.isNullOrEmpty() || version.isNullOrEmpty()) {
163-
return null
164-
}
165-
val dependency = AxonDependency.entries.firstOrNull { it.groupId == groupId && it.artifactId == artifactId }
166-
if(dependency == null) {
158+
try {
159+
val groupId = properties.getProperty("groupId")
160+
val artifactId = properties.getProperty("artifactId")
161+
val version = properties.getProperty("version")
162+
if (groupId.isNullOrEmpty() || artifactId.isNullOrEmpty() || version.isNullOrEmpty()) {
163+
return null
164+
}
165+
val dependency = AxonDependency.entries.firstOrNull { it.groupId == groupId && it.artifactId == artifactId }
166+
if (dependency == null) {
167+
return null
168+
}
169+
val (majorVersion, minorVersion, patchVersion, remaining) = versionRegex.find(version)?.destructured ?: return null
170+
return AxonDependencyVersion(
171+
dependency,
172+
Integer.parseInt(majorVersion),
173+
Integer.parseInt(minorVersion),
174+
Integer.parseInt(patchVersion),
175+
remaining
176+
)
177+
} catch (e: Exception) {
178+
// Ignore
167179
return null
168180
}
169-
val (majorVersion, minorVersion, patchVersion, remaining) = versionRegex.find(version)!!.destructured
170-
return AxonDependencyVersion(
171-
dependency,
172-
Integer.parseInt(majorVersion),
173-
Integer.parseInt(minorVersion),
174-
Integer.parseInt(patchVersion),
175-
remaining
176-
)
177181
}
178182

179183
data class AxonDependencyVersion(

0 commit comments

Comments
 (0)