Skip to content

Commit

Permalink
fix(gui): handle paths where file name is null (#2136)(PR #2137)
Browse files Browse the repository at this point in the history
* fix: Ignore invalid files

Avoid NullPointerException when using "Open files" or drag-n-drop

* refactor: Replace Stream API chain with loop

IntelliJ

* fix: Ignore invalid files

Avoid NullPointerException when using "Add files"

* fix: Fall back to complete path string

Instead of empty project name

* fix: Render tree

Project tree (sidebar) didn’t load
Toggling "View > Show flatten packages" threw a NPE here

* fix code formatting

---------

Co-authored-by: Skylot <skylot@gmail.com>
  • Loading branch information
xnumad and skylot committed Mar 29, 2024
1 parent 2807dc5 commit 6b4976c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
19 changes: 14 additions & 5 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -113,11 +114,19 @@ public void setFilePaths(List<Path> files) {
} else {
Collections.sort(files);
data.setFiles(files);
String joinedName = files.stream()
.map(p -> p.getFileName().toString())
.filter(file -> !file.endsWith(".jadx.kts"))
.map(CommonFileUtils::removeFileExtension)
.collect(Collectors.joining("_"));
StringJoiner joiner = new StringJoiner("_");
for (Path p : files) {
Path fileNamePart = p.getFileName();
if (fileNamePart == null) {
joiner.add(p.toString());
continue;
}
String fileName = fileNamePart.toString();
if (!fileName.endsWith(".jadx.kts")) {
joiner.add(CommonFileUtils.removeFileExtension(fileName));
}
}
String joinedName = joiner.toString();
name = StringUtils.abbreviate(joinedName, 100);
}
changed();
Expand Down
6 changes: 5 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ public String makeString() {
return "File not open";
}
if (count == 1) {
return paths.get(0).getFileName().toString();
Path fileNamePath = paths.get(0).getFileName();
if (fileNamePath != null) {
return fileNamePath.toString();
}
return paths.get(0).toString();
}
return count + " files";
}
Expand Down
3 changes: 3 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ private void open(List<Path> paths, Runnable onFinish) {
}

private boolean openSingleFile(Path singleFile, Runnable onFinish) {
if (singleFile.getFileName() == null) {
return false;
}
String fileExtension = CommonFileUtils.getFileExtension(singleFile.getFileName().toString());
if (fileExtension != null && fileExtension.equalsIgnoreCase(JadxProject.PROJECT_EXTENSION)) {
openProject(singleFile, onFinish);
Expand Down

0 comments on commit 6b4976c

Please sign in to comment.