Skip to content

Commit 13adb55

Browse files
committed
fix(core): handle null project base path and patch names
Add null safety checks for project.basePath and patch.beforeName/afterName properties. Fall back to current directory when project base path is unavailable and use empty strings for null patch names.
1 parent 529b384 commit 13adb55

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/ui/patch/SingleFileDiffSketch.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ class SingleFileDiffSketch(
181181

182182
if (myProject.coderSetting.state.enableDiffViewer && appliedPatch?.status == ApplyPatchStatus.SUCCESS) {
183183
patchProcessor.registerPatchChange(patch)
184-
// 默认不显示 diffPanel,通过点击图标按钮来控制显示/隐藏
185184
diffPanel = createDiffViewer(oldCode, newCode)
186-
// diffPanel 将由 toggleButton 控制显示
187185
}
188186
}
189187

core/src/main/kotlin/cc/unitmesh/devti/util/PatchConverter.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ object PatchConverter {
3838
}
3939

4040
fun createChange(project: Project, patch: TextFilePatch): Change {
41-
val baseDir = File(project.basePath!!)
42-
val beforePath = patch.beforeName
43-
val afterPath = patch.afterName
41+
val basePath = project.basePath
42+
if (basePath == null) {
43+
logger<PatchConverter>().warn("Project base path is null, using current directory")
44+
}
45+
46+
val baseDir = File(basePath ?: System.getProperty("user.dir"))
47+
val beforePath = patch.beforeName ?: ""
48+
val afterPath = patch.afterName ?: ""
4449

4550
val fileStatus = when {
4651
patch.isNewFile -> {

0 commit comments

Comments
 (0)