From 3c53d40efba140177df9d26316e53d1807196baa Mon Sep 17 00:00:00 2001 From: Peter Monks Date: Thu, 14 Sep 2023 12:57:46 -0700 Subject: [PATCH] :ambulance: Address issue #203 --- .../spdx/library/model/SpdxModelFactory.java | 2 +- .../license/LicenseExpressionParser.java | 2 +- .../model/license/LicenseInfoFactory.java | 2 +- .../library/model/license/ListedLicenses.java | 10 +++---- .../model/license/SpdxListedLicense.java | 4 +-- .../referencetype/ListedReferenceTypes.java | 8 +++--- .../SpdxListedLicenseModelStore.java | 26 +++++++++---------- .../SpdxListedLicenseWebStore.java | 2 +- .../spdx/storage/simple/StoredTypedItem.java | 6 ++--- .../utility/compare/LicenseCompareHelper.java | 4 +-- .../spdx/utility/compare/SpdxComparer.java | 2 +- .../utility/compare/SpdxSnippetComparer.java | 8 +++--- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/spdx/library/model/SpdxModelFactory.java b/src/main/java/org/spdx/library/model/SpdxModelFactory.java index 83759abe9..134122763 100644 --- a/src/main/java/org/spdx/library/model/SpdxModelFactory.java +++ b/src/main/java/org/spdx/library/model/SpdxModelFactory.java @@ -294,7 +294,7 @@ public static Optional getModelObject(IModelStore modelStore, Strin try { return Optional.of(new ExternalSpdxElement(modelStore, documentUri, id, copyManager, true)); } catch(InvalidSPDXAnalysisException ex) { - logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty"); + logger.warn("Attempting to get a model object for an invalid SPDX ID. Returning empty", ex); return Optional.empty(); } } diff --git a/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java b/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java index 79cc6a3c0..b6024b350 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java +++ b/src/main/java/org/spdx/library/model/license/LicenseExpressionParser.java @@ -93,7 +93,7 @@ static AnyLicenseInfo parseLicenseExpression(String expression, IModelStore stor // Add the expression to the error message to provide additional information to the user throw new LicenseParserException(ex.getMessage()+" License expression: '"+expression+"'", ex); } catch (EmptyStackException ex) { - throw new LicenseParserException("Invalid license expression: '"+expression+"' - check that every operator (e.g. AND and OR) has operators and that parenthesis are matched"); + throw new LicenseParserException("Invalid license expression: '"+expression+"' - check that every operator (e.g. AND and OR) has operators and that parenthesis are matched", ex); } } } diff --git a/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java b/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java index 4a2d5b547..5ef1ed1a9 100644 --- a/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java +++ b/src/main/java/org/spdx/library/model/license/LicenseInfoFactory.java @@ -87,7 +87,7 @@ public static AnyLicenseInfo parseSPDXLicenseString(String licenseString, @Nulla } catch (LicenseParserException e) { throw new InvalidLicenseStringException(e.getMessage(),e); } catch (InvalidSPDXAnalysisException e) { - throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string"); + throw new InvalidLicenseStringException("Unexpected SPDX error parsing license string", e); } } diff --git a/src/main/java/org/spdx/library/model/license/ListedLicenses.java b/src/main/java/org/spdx/library/model/license/ListedLicenses.java index 79f9caecd..5c101638c 100644 --- a/src/main/java/org/spdx/library/model/license/ListedLicenses.java +++ b/src/main/java/org/spdx/library/model/license/ListedLicenses.java @@ -85,13 +85,13 @@ private static Properties loadLicenseProperties() { } } catch (IOException e) { // Ignore it and fall through - logger.warn("IO Exception reading listed license properties file: " + e.getMessage()); + logger.warn("IO Exception reading listed license properties file: " + e.getMessage(), e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { - logger.warn("Unable to close listed license properties file: " + e.getMessage()); + logger.warn("Unable to close listed license properties file: " + e.getMessage(), e); } } } @@ -108,7 +108,7 @@ private void initializeLicenseModelStore() { try { licenseModelStore = new SpdxListedLicenseWebStore(); } catch(InvalidSPDXAnalysisException ex) { - logger.error("Unable to access the most current listed licenses from https://spdx.org/licenses - using locally cached licenses: "+ex.getMessage()); + logger.error("Unable to access the most current listed licenses from https://spdx.org/licenses - using locally cached licenses: "+ex.getMessage(), ex); licenseModelStore = null; } } @@ -116,8 +116,8 @@ private void initializeLicenseModelStore() { try { licenseModelStore = new SpdxListedLicenseLocalStore(); } catch(InvalidSPDXAnalysisException ex) { - logger.error("Error loading cached SPDX licenses"); - throw new RuntimeException("Unexpected error loading SPDX Listed Licenses"); + logger.error("Error loading cached SPDX licenses", ex); + throw new RuntimeException("Unexpected error loading SPDX Listed Licenses", ex); } } } finally { diff --git a/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java b/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java index 1ac7893cc..43b781329 100644 --- a/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java +++ b/src/main/java/org/spdx/library/model/license/SpdxListedLicense.java @@ -146,7 +146,7 @@ public String getLicenseTextHtml() throws InvalidLicenseTemplateException, Inval try { return SpdxLicenseTemplateHelper.templateTextToHtml(templateText); } catch(LicenseTemplateRuleException ex) { - throw new InvalidLicenseTemplateException("Invalid license expression found in license text for license "+getName()+":"+ex.getMessage()); + throw new InvalidLicenseTemplateException("Invalid license expression found in license text for license "+getName()+":"+ex.getMessage(), ex); } } else { return SpdxLicenseTemplateHelper.formatEscapeHTML(this.getLicenseText()); @@ -179,7 +179,7 @@ public String getLicenseHeaderHtml() throws InvalidLicenseTemplateException, Inv try { return SpdxLicenseTemplateHelper.templateTextToHtml(templateText); } catch(LicenseTemplateRuleException ex) { - throw new InvalidLicenseTemplateException("Invalid license expression found in standard license header for license "+getName()+":"+ex.getMessage()); + throw new InvalidLicenseTemplateException("Invalid license expression found in standard license header for license "+getName()+":"+ex.getMessage(), ex); } } else { return SpdxLicenseTemplateHelper.formatEscapeHTML(this.getStandardLicenseHeader()); diff --git a/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java b/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java index f25990a22..2d689bfd9 100644 --- a/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java +++ b/src/main/java/org/spdx/library/referencetype/ListedReferenceTypes.java @@ -66,7 +66,7 @@ private ListedReferenceTypes() { } } catch (IOException e) { logger.warn("IO Exception reading listed reference type properties file: " - + e.getMessage() + ", loading properties from class properties file."); + + e.getMessage() + ", loading properties from class properties file.", e); } if (Objects.isNull(in)) { try { @@ -77,7 +77,7 @@ private ListedReferenceTypes() { logger.error("Unable to load listed reference type properties"); } } catch (IOException ex2) { - logger.error("IO exception reading listed reference type properties from class properties file: "+ex2.getMessage()); + logger.error("IO exception reading listed reference type properties from class properties file: "+ex2.getMessage(), ex2); } } } finally { @@ -85,7 +85,7 @@ private ListedReferenceTypes() { try { in.close(); } catch (IOException e) { - logger.warn("Unable to close listed license properties file: " + e.getMessage()); + logger.warn("Unable to close listed license properties file: " + e.getMessage(), e); } } } @@ -165,7 +165,7 @@ public URI getListedReferenceUri(String listedReferenceName) throws InvalidSPDXA retval = new URI(SpdxConstants.SPDX_LISTED_REFERENCE_TYPES_PREFIX + listedReferenceName); } catch (URISyntaxException e) { logger.error("Error forming listed license URI",e); - throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type syntax."); + throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type syntax.",e); } if (!isListedReferenceType(retval)) { throw new InvalidSPDXAnalysisException(listedReferenceName + " is not a valid SPDX listed reference type."); diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java index 1f0395977..e49a53918 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java @@ -170,15 +170,15 @@ private void loadIds() throws InvalidSPDXAnalysisException { ExceptionJsonTOC exceptionToc = gson.fromJson(tocJsonStr.toString(), ExceptionJsonTOC.class); exceptionIds = exceptionToc.getExceptionIds(); } catch (MalformedURLException e) { - throw new SpdxListedLicenseException("License TOC URL invalid") ; + throw new SpdxListedLicenseException("License TOC URL invalid", e) ; } catch (IOException e) { - throw new SpdxListedLicenseException("I/O error reading license TOC"); + throw new SpdxListedLicenseException("I/O error reading license TOC", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); + logger.warn("Unable to close JSON TOC reader", e); } } } @@ -326,23 +326,23 @@ private LicenseJson fetchLicenseJson(String idCaseInsensitive) throws InvalidSPD LicenseJson license = gson.fromJson(licenseJsonStr.toString(), LicenseJson.class); this.listedLicenseCache.put(id, license); } catch (MalformedURLException e) { - logger.error("Json license invalid for ID "+id); - throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); + logger.error("Json license invalid for ID "+id, e); + throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id, e); } catch (IOException e) { - logger.error("I/O error opening Json license URL"); - throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); + logger.error("I/O error opening Json license URL", e); + throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id, e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); + logger.warn("Unable to close JSON TOC reader", e); } } else if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { - logger.warn("Unable to close JSON TOC input stream"); + logger.warn("Unable to close JSON TOC input stream", e); } } } @@ -398,22 +398,22 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali this.listedExceptionCache.put(id, exc); } catch (MalformedURLException e) { logger.error("Json license invalid for ID "+id); - throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id); + throw new SpdxListedLicenseException("JSON license URL invalid for ID "+id, e); } catch (IOException e) { logger.error("I/O error opening Json license URL"); - throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id); + throw new SpdxListedLicenseException("I/O Error reading license data for ID "+id, e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { - logger.warn("Unable to close JSON TOC reader"); + logger.warn("Unable to close JSON TOC reader", e); } } else if (jsonStream != null) { try { jsonStream.close(); } catch (IOException e) { - logger.warn("Unable to close JSON TOC input stream"); + logger.warn("Unable to close JSON TOC input stream", e); } } } diff --git a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java index 068974dbd..4aaf3c3e4 100644 --- a/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java +++ b/src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java @@ -63,7 +63,7 @@ private InputStream getUrlInputStream(URL url) throws IOException { try { redirectUrl = new URL(redirectUrlStr); } catch(Exception ex) { - throw new IOException("Invalid redirect URL"); + throw new IOException("Invalid redirect URL", ex); } if (!redirectUrl.getProtocol().toLowerCase().startsWith("http")) { throw new IOException("Invalid redirect protocol"); diff --git a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java index 41275396b..08c19290d 100644 --- a/src/main/java/org/spdx/storage/simple/StoredTypedItem.java +++ b/src/main/java/org/spdx/storage/simple/StoredTypedItem.java @@ -200,7 +200,7 @@ public boolean addValueToList(String propertyName, Object value) throws SpdxInva } return list.add(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyName, ex); } } @@ -222,7 +222,7 @@ public boolean removeTypedValueFromList(String propertyName, TypedValue value) t } return list.remove(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyName, ex); } } @@ -257,7 +257,7 @@ public boolean removeValueFromList(String propertyName, Object value) throws Spd } return list.remove(value); } catch (Exception ex) { - throw new SpdxInvalidTypeException("Invalid list type for "+propertyName); + throw new SpdxInvalidTypeException("Invalid list type for "+propertyName, ex); } } diff --git a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java index c0a0418ca..8c8d6a014 100644 --- a/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java +++ b/src/main/java/org/spdx/utility/compare/LicenseCompareHelper.java @@ -244,14 +244,14 @@ public static String removeCommentChars(String s) { } return sb.toString(); } catch (IOException e) { - logger.warn("IO error reading strings?!?"); + logger.warn("IO error reading strings?!?", e); return s; } finally { if (Objects.nonNull(reader)) { try { reader.close(); } catch (IOException e) { - logger.warn("IO error closing a string reader?!?"); + logger.warn("IO error closing a string reader?!?", e); } } } diff --git a/src/main/java/org/spdx/utility/compare/SpdxComparer.java b/src/main/java/org/spdx/utility/compare/SpdxComparer.java index da488c67c..3ec961fa0 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxComparer.java @@ -901,7 +901,7 @@ private void compareDocumentContents() throws SpdxCompareException { } } } catch(InvalidSPDXAnalysisException ex) { - throw new SpdxCompareException("Error getting SPDX document items: "+ex.getMessage()); + throw new SpdxCompareException("Error getting SPDX document items: "+ex.getMessage(), ex); } } diff --git a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java index 057e493d4..d8cf0bf8b 100644 --- a/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java +++ b/src/main/java/org/spdx/utility/compare/SpdxSnippetComparer.java @@ -91,7 +91,7 @@ public void addDocumentSnippet(SpdxDocument spdxDocument, this.differenceFound = true; } } catch (InvalidSPDXAnalysisException e) { - throw new SpdxCompareException("SPDX error getting byte range: "+e.getMessage()); + throw new SpdxCompareException("SPDX error getting byte range: "+e.getMessage(), e); } try { Optional lineRange = snippet.getLineRange(); @@ -111,14 +111,14 @@ public void addDocumentSnippet(SpdxDocument spdxDocument, this.differenceFound = true; } } catch (InvalidSPDXAnalysisException e) { - throw new SpdxCompareException("SPDX error getting line range: "+e.getMessage()); + throw new SpdxCompareException("SPDX error getting line range: "+e.getMessage(), e); } try { SpdxFile fromFile = snippet.getSnippetFromFile(); SpdxFile fromFile2 = snippet2.getSnippetFromFile(); compareSnippetFromFiles(spdxDocument, fromFile, document2, fromFile2); } catch (InvalidSPDXAnalysisException e) { - throw new SpdxCompareException("SPDX error getting snippet from file: "+e.getMessage()); + throw new SpdxCompareException("SPDX error getting snippet from file: "+e.getMessage(), e); } try { if (!SpdxComparer.stringsEqual(snippet2.getName(), snippet.getName())) { @@ -126,7 +126,7 @@ public void addDocumentSnippet(SpdxDocument spdxDocument, this.differenceFound = true; } } catch (InvalidSPDXAnalysisException e) { - throw new SpdxCompareException("SPDX error comparing snippet names: "+e.getMessage()); + throw new SpdxCompareException("SPDX error comparing snippet names: "+e.getMessage(), e); } } inProgress = false;