From d8891a18c658718cc288eafe206b5af964c9b783 Mon Sep 17 00:00:00 2001 From: Craig Wisniewski Date: Wed, 20 Oct 2021 10:40:48 +1030 Subject: [PATCH] fix for NPE in library.listTokenLibraries() --- .../maptool/model/framework/LibraryToken.java | 31 +++++++++++-------- .../rptools/maptool/language/i18n.properties | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/rptools/maptool/model/framework/LibraryToken.java b/src/main/java/net/rptools/maptool/model/framework/LibraryToken.java index 3c766822ad..3587d1b836 100644 --- a/src/main/java/net/rptools/maptool/model/framework/LibraryToken.java +++ b/src/main/java/net/rptools/maptool/model/framework/LibraryToken.java @@ -58,10 +58,10 @@ class LibraryToken implements Library { /** The name of the property for the license information. */ private static final String LIB_LICENSE_PROPERTY_NAME = "liblicense"; - /** The name of the property for the description of the l;ibrary. */ + /** The name of the property for the description of the library. */ private static final String LIB_DESCRIPTION_PROPERTY_NAME = "libdescription"; - /** The name of the property for the short description of the l;ibrary. */ + /** The name of the property for the short description of the library. */ private static final String LIB_SHORT_DESCRIPTION_PROPERTY_NAME = "libshortdescription"; /** The version number to return if the lin:token version is unknown. */ @@ -279,21 +279,21 @@ public CompletableFuture getLibraryInfo() { return new ThreadExecutionHelper() .runOnSwingThread( () -> { + String notSet = I18N.getText("library.property.value.notSpecified"); Token library = findLibrary(id); + String authorsString = getProperty(LIB_AUTHORS_PROPERTY_NAME, notSet); var authors = - Arrays.stream(getProperty(LIB_AUTHORS_PROPERTY_NAME, "").split(",")) - .map(String::trim) - .toArray(String[]::new); + Arrays.stream(authorsString.split(",")).map(String::trim).toArray(String[]::new); return new LibraryInfo( library.getName(), - library.getName(), - getProperty(LIB_VERSION_PROPERTY_NAME), - getProperty(LIB_WEBSITE_PROPERTY_NAME), - getProperty(LIB_GITURL_PROPERTY_NAME), + library.getName().substring(4), + getProperty(LIB_VERSION_PROPERTY_NAME, notSet), + getProperty(LIB_WEBSITE_PROPERTY_NAME, notSet), + getProperty(LIB_GITURL_PROPERTY_NAME, notSet), authors, - getProperty(LIB_LICENSE_PROPERTY_NAME), - getProperty(LIB_DESCRIPTION_PROPERTY_NAME), - getProperty(LIB_SHORT_DESCRIPTION_PROPERTY_NAME), + getProperty(LIB_LICENSE_PROPERTY_NAME, notSet), + getProperty(LIB_DESCRIPTION_PROPERTY_NAME, notSet), + getProperty(LIB_SHORT_DESCRIPTION_PROPERTY_NAME, notSet), library.getAllowURIAccess()); }); } @@ -428,7 +428,12 @@ private String getMacroText(String name) { private String getProperty(String name) { var token = findLibrary(id); - return token.getProperty(name).toString(); + Object prop = token.getProperty(name); + if (prop == null) { + return null; + } else { + return prop.toString(); + } } /** diff --git a/src/main/resources/net/rptools/maptool/language/i18n.properties b/src/main/resources/net/rptools/maptool/language/i18n.properties index 8aaaaae3f8..bc4065522a 100644 --- a/src/main/resources/net/rptools/maptool/language/i18n.properties +++ b/src/main/resources/net/rptools/maptool/language/i18n.properties @@ -2586,3 +2586,4 @@ library.error.libtoken.missing = Lib:Token can no longer be found. library.error.addOnLibraryExists = Add-On Library with namespace {0} already exists. Do you want to replace it? library.error.addOn.notText = Can't convert asset of type {0} to text. library.error.addOn.noConfigFile = library.josn file not found in {0}. +library.property.value.notSpecified = Not Specified