From 36548038964315ad1301284f244b4e2e30dae719 Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Sat, 19 Feb 2022 00:42:39 +0100
Subject: [PATCH] #676 - fixed update of missing attributes

---
 .../budgetmaster/accounts/AccountService.java       | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java b/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java
index 58a75b694..6a8e14ba9 100644
--- a/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java
+++ b/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java
@@ -127,7 +127,9 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A
 		if(accountRepository.findAll().isEmpty())
 		{
 			Account placeholder = new Account("Placeholder", AccountType.ALL);
-			placeholder.updateIcon(iconService, null, PLACEHOLDER_ICON, null, this);
+			final Icon newIcon = iconService.createIconReference(null, PLACEHOLDER_ICON, null);
+			iconService.getRepository().save(newIcon);
+			placeholder.setIconReference(newIcon);
 			accountRepository.save(placeholder);
 			LOGGER.debug("Created placeholder account");
 
@@ -158,7 +160,14 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A
 
 		final Account placeholderAccount = accountRepository.findAllByType(AccountType.ALL).get(0);
 		final Icon icon = placeholderAccount.getIconReference();
-		if(icon.getBuiltinIdentifier() == null)
+		if(icon == null)
+		{
+			final Icon newIcon = iconService.createIconReference(null, PLACEHOLDER_ICON, null);
+			iconService.getRepository().save(newIcon);
+			placeholderAccount.setIconReference(newIcon);
+			LOGGER.debug(MessageFormat.format("Updated placeholder account: Created missing icon instance and set icon to \"{0}\"", PLACEHOLDER_ICON));
+		}
+		else if(icon.getBuiltinIdentifier() == null)
 		{
 			placeholderAccount.updateIcon(iconService, null, PLACEHOLDER_ICON, null, this);
 			LOGGER.debug(MessageFormat.format("Updated placeholder account: Set missing icon to \"{0}\"", PLACEHOLDER_ICON));
-- 
GitLab