fix(gui): resolve possible NPE during project data loading (#2794)

This commit is contained in:
Skylot
2026-02-18 20:28:43 +00:00
parent dfe1d0477d
commit b0954e9620
12 changed files with 24 additions and 48 deletions
@@ -61,10 +61,15 @@ public class JadxProject {
private transient boolean initial = true;
private transient boolean saved;
private ProjectData data = new ProjectData();
private final ProjectData data;
public JadxProject(MainWindow mainWindow) {
this(mainWindow, new ProjectData());
}
private JadxProject(MainWindow mainWindow, ProjectData projectData) {
this.mainWindow = mainWindow;
this.data = Objects.requireNonNull(projectData);
}
public void fillJadxArgs(JadxArgs jadxArgs) {
@@ -312,16 +317,11 @@ public class JadxProject {
}
public static JadxProject load(MainWindow mainWindow, Path path) {
try {
JadxProject project = new JadxProject(mainWindow);
project.data = loadProjectData(path);
project.saved = true;
project.setProjectPath(path);
return project;
} catch (Exception e) {
LOG.error("Error loading project", e);
return null;
}
ProjectData projectData = loadProjectData(path);
JadxProject project = new JadxProject(mainWindow, projectData);
project.saved = true;
project.setProjectPath(path);
return project;
}
public static ProjectData loadProjectData(Path path) {
@@ -551,17 +551,8 @@ public class MainWindow extends JFrame {
private void openProject(Path path, Runnable onFinish) {
LOG.debug("Loading project: {}", path);
JadxProject jadxProject = JadxProject.load(this, path);
if (jadxProject == null) {
JOptionPane.showMessageDialog(
this,
NLS.str("msg.project_error"),
NLS.str("msg.project_error_title"),
JOptionPane.INFORMATION_MESSAGE);
jadxProject = new JadxProject(this);
}
project = JadxProject.load(this, path);
settings.addRecentProject(path);
project = jadxProject;
loadFiles(onFinish);
}
@@ -379,9 +379,12 @@ public class UiUtils {
}
public static void errorMessage(Component parent, String message) {
errorMessage(parent, NLS.str("message.errorTitle"), message);
}
public static void errorMessage(Component parent, String title, String message) {
LOG.error(message);
JOptionPane.showMessageDialog(parent, message,
NLS.str("message.errorTitle"), JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
}
public static void copyToClipboard(String text) {
@@ -347,8 +347,6 @@ msg.language_changed=Die neue Sprache wird beim nächsten Start der Anwendung an
msg.warning_title=Warnung
msg.common_mouse_shortcut=Dies ist eine häufig verwendete Taste. Möchtest du sie wirklich an eine Aktion binden?
msg.duplicate_shortcut=Der Tastenkürzel %s ist bereits in der Aktion „%s“ aus der Kategorie „%s“ festgelegt, fortfahren?
msg.project_error_title=Fehler
msg.project_error=Projekt konnte nicht geladen werden
msg.cmd_select_class_error=Klasse\n%s auswählen nicht möglich\nSie existiert nicht.
msg.cant_add_comment=Kann hier keinen Kommentar hinzufügen
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ action_category.plugin_script=Plugin-Skript
#graph_viewer.method_graph.title=Methods Graph
#graph_viewer.call_graph.title=Call Graph
#graph_viewer.inheritance_graph.title=Inheritance Graph
#graph_viewer.cfg.title=Control Flow Graph
#graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=New language will be displayed the next time application st
msg.warning_title=Warning
msg.common_mouse_shortcut=This is a commonly used key, are you sure you would like to bind it to an action?
msg.duplicate_shortcut=The shortcut %s is already set in action "%s" from category "%s", continue ?
msg.project_error_title=Error
msg.project_error=Project could not be loaded
msg.cmd_select_class_error=Failed to select the class\n%s\nThe class does not exist.
msg.cant_add_comment=Can't add comment here
msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ graph_viewer.default_title=Graph Viewer
graph_viewer.method_graph.title=Methods Graph
graph_viewer.call_graph.title=Call Graph
graph_viewer.inheritance_graph.title=Inheritance Graph
graph_viewer.cfg.title=Control Flow Graph
graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=El nuevo idioma se mostrará la próxima vez que la aplicac
#msg.warning_title=Warning
#msg.common_mouse_shortcut=This is a commonly used key, are you sure you would like to bind it to an action?
#msg.duplicate_shortcut=The shortcut %s is already set in action "%s" from category "%s", continue ?
#msg.project_error_title=Error
#msg.project_error=Project could not be loaded
#msg.cmd_select_class_error=Failed to select the class\n%s\nThe class does not exist.
#msg.cant_add_comment=Can't add comment here
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ certificate.serialPubKeyY=Y
#graph_viewer.method_graph.title=Methods Graph
#graph_viewer.call_graph.title=Call Graph
#graph_viewer.inheritance_graph.title=Inheritance Graph
#graph_viewer.cfg.title=Control Flow Graph
#graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=Bahasa baru akan ditampilkan saat aplikasi dimulai kembali.
msg.warning_title=Peringatan
msg.common_mouse_shortcut=Ini adalah tombol yang sering digunakan, apakah Anda yakin ingin mengaitkannya dengan tindakan?
msg.duplicate_shortcut=Pintas %s sudah diatur pada tindakan "%s" dari kategori "%s", lanjutkan?
msg.project_error_title=Kesalahan
msg.project_error=Proyek tidak dapat dimuat
msg.cmd_select_class_error=Gagal memilih kelas\n%s\nKelas tidak ada.
msg.cant_add_comment=Tidak dapat menambahkan komentar di sini
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ action_category.plugin_script=Plugin Script
#graph_viewer.method_graph.title=Methods Graph
#graph_viewer.call_graph.title=Call Graph
#graph_viewer.inheritance_graph.title=Inheritance Graph
#graph_viewer.cfg.title=Control Flow Graph
#graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=다음에 응용 프로그램이 시작되면 새 언어가
#msg.warning_title=Warning
#msg.common_mouse_shortcut=This is a commonly used key, are you sure you would like to bind it to an action?
#msg.duplicate_shortcut=The shortcut %s is already set in action "%s" from category "%s", continue ?
msg.project_error_title=오류
msg.project_error=프로젝트를 로드 할 수 없습니다.
msg.cmd_select_class_error=클래스를 선택하지 못했습니다.\n%s\n클래스가 없습니다.
msg.cant_add_comment=여기에 주석을 추가할수 없음
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -347,8 +347,6 @@ msg.language_changed=Novo idioma será mostrado na próxima inicialização.
#msg.warning_title=Warning
#msg.common_mouse_shortcut=This is a commonly used key, are you sure you would like to bind it to an action?
#msg.duplicate_shortcut=The shortcut %s is already set in action "%s" from category "%s", continue ?
msg.project_error_title=Erro
msg.project_error=Projeto não pôde ser carregado
msg.cmd_select_class_error=Falha ao selecionar classe\n%s\nA classe não existe.
msg.cant_add_comment=Não é possível adicionar comentários aqui
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ adb_dialog.starting_debugger=Iniciando depurador...
#graph_viewer.method_graph.title=Methods Graph
#graph_viewer.call_graph.title=Call Graph
#graph_viewer.inheritance_graph.title=Inheritance Graph
#graph_viewer.cfg.title=Control Flow Graph
#graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=Новый язык применится при следу
msg.warning_title=Внимание
msg.common_mouse_shortcut=Это часто распространенная комбинация, вы действительно хотите назначить ее?
msg.duplicate_shortcut=Действие %s уже выполняет "%s" в категории "%s", продолжить?
msg.project_error_title=Ошибка
msg.project_error=Проект не может быть загружен
msg.cmd_select_class_error=Ошибка выбора класса\n%s\nЭтот класс не существует.
msg.cant_add_comment=Невозможно добавить комментарий сюда
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?
@@ -553,4 +551,4 @@ action_category.plugin_script=Скрипты и плагины
#graph_viewer.method_graph.title=Methods Graph
#graph_viewer.call_graph.title=Call Graph
#graph_viewer.inheritance_graph.title=Inheritance Graph
#graph_viewer.cfg.title=Control Flow Graph
#graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=新的语言将在下次应用程序启动时显示。
msg.warning_title=警告
msg.common_mouse_shortcut=这是常用按键,您确定要绑定操作吗?
msg.duplicate_shortcut=快捷键 %s 已设为操作 “%s”,位于群组 “%s”。确定要继续吗?
msg.project_error_title=错误
msg.project_error=项目无法加载
msg.cmd_select_class_error=无法选择类\n%s\n该类不存在。
msg.cant_add_comment=无法在此添加注释
msg.non_displayable_chars=部分字符在当前使用的字体“%s”中无法显示,是否显示这些字符?
@@ -553,4 +551,4 @@ graph_viewer.default_title=Graph Viewer
graph_viewer.method_graph.title=Methods Graph
graph_viewer.call_graph.title=Call Graph
graph_viewer.inheritance_graph.title=Inheritance Graph
graph_viewer.cfg.title=Control Flow Graph
graph_viewer.cfg.title=Control Flow Graph
@@ -347,8 +347,6 @@ msg.language_changed=新語言將於下次應用程式啟動時套用。
msg.warning_title=警告
msg.common_mouse_shortcut=這是常用按鍵,您確定要綁定操作嗎?
msg.duplicate_shortcut=快捷鍵 %s 已設為操作 "%s",位於群組 "%s"。確定要繼續嗎?
msg.project_error_title=錯誤
msg.project_error=無法載入專案
msg.cmd_select_class_error=無法選擇類別\n%s\n類別不存在。
msg.cant_add_comment=無法在此新增註解
#msg.non_displayable_chars=Some characters were found in code are not displayable by currently used font "%s". Show chars?