Skip to content

Commit

Permalink
Fixes a NPE when the security properties contain a null value
Browse files Browse the repository at this point in the history
Issue: #3895
  • Loading branch information
buchen committed Apr 2, 2024
1 parent 6f11cc3 commit a279970
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Properties // NOSONAR
String WATCHLISTS = "watchlists"; //$NON-NLS-1$
}

public static final int CURRENT_VERSION = 59;
public static final int CURRENT_VERSION = 60;
public static final int VERSION_WITH_CURRENCY_SUPPORT = 29;
public static final int VERSION_WITH_UNIQUE_FILTER_KEY = 57;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ else if (flags.contains(SaveFlag.COMPRESSED))
removeWronglyAddedSecurities(client);
case 58:
fixDataSeriesLabelForAccumulatedTaxes(client);
case 59:
fixNullSecurityProperties(client);

client.setVersion(Client.CURRENT_VERSION);
break;
Expand Down Expand Up @@ -1551,6 +1553,24 @@ private static void fixDataSeriesLabelForAccumulatedTaxes(Client client)
.replace("Client-taxes;", "Client-taxes_accumulated;"))); //$NON-NLS-1$ //$NON-NLS-2$
}

private static void fixNullSecurityProperties(Client client)
{
// see https://github.com/portfolio-performance/portfolio/issues/3895

for (Security security : client.getSecurities())
{
var properties = security.getProperties().toList();

for (SecurityProperty p : properties)
{
if (p == null)
{
security.removeProperty(null);
}
}
}
}

@SuppressWarnings("nls")
private static synchronized XStream xstream()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,8 @@ private void saveSecurities(Client client, PClient.Builder newClient)

Map<String, PMap.Builder> data = new HashMap<>();
security.getProperties().forEach(p -> {
if (p == null)
return;
PMap.Builder map = data.computeIfAbsent(p.getType().name(), k -> PMap.newBuilder());
map.addEntries(PKeyValue.newBuilder().setKey(p.getName())
.setValue(PAnyValue.newBuilder().setString(p.getValue())).build());
Expand Down

0 comments on commit a279970

Please sign in to comment.