@@ -150,7 +150,7 @@ private void loadIds() throws InvalidSPDXAnalysisException {
150150 try {
151151 // read the license IDs
152152 tocStream = getTocInputStream ();
153- reader = new BufferedReader (new InputStreamReader (tocStream ));
153+ reader = new BufferedReader (new InputStreamReader (tocStream , "UTF-8" ));
154154 StringBuilder tocJsonStr = new StringBuilder ();
155155 String line ;
156156 while ((line = reader .readLine ()) != null ) {
@@ -162,17 +162,17 @@ private void loadIds() throws InvalidSPDXAnalysisException {
162162
163163 // read the exception ID's
164164 tocStream = getExceptionTocInputStream ();
165- reader = new BufferedReader (new InputStreamReader (tocStream ));
165+ reader = new BufferedReader (new InputStreamReader (tocStream , "UTF-8" ));
166166 tocJsonStr = new StringBuilder ();
167167 while ((line = reader .readLine ()) != null ) {
168168 tocJsonStr .append (line );
169169 }
170170 ExceptionJsonTOC exceptionToc = gson .fromJson (tocJsonStr .toString (), ExceptionJsonTOC .class );
171171 exceptionIds = exceptionToc .getExceptionIds ();
172172 } catch (MalformedURLException e ) {
173- throw ( new SpdxListedLicenseException ("License TOC URL invalid" )) ;
173+ throw new SpdxListedLicenseException ("License TOC URL invalid" ) ;
174174 } catch (IOException e ) {
175- throw ( new SpdxListedLicenseException ("I/O error reading license TOC" ) );
175+ throw new SpdxListedLicenseException ("I/O error reading license TOC" );
176176 } finally {
177177 if (reader != null ) {
178178 try {
@@ -195,9 +195,14 @@ public boolean exists(String documentUri, String id) {
195195 if (!SpdxConstants .LISTED_LICENSE_URL .equals (documentUri )) {
196196 return false ;
197197 }
198+ listedLicenseModificationLock .readLock ().lock ();
199+ try {
198200 return this .licenseIds .containsKey (id .toLowerCase ()) ||
199201 this .exceptionIds .containsKey (id .toLowerCase ()) ||
200202 this .crossRefs .containsKey (id );
203+ } finally {
204+ listedLicenseModificationLock .readLock ().unlock ();
205+ }
201206 }
202207
203208 /* (non-Javadoc)
@@ -260,21 +265,21 @@ public List<String> getPropertyValueNames(String documentUri, String id) throws
260265 } else if (crossRefs .containsKey (id )) {
261266 crossRef = crossRefs .get (id );
262267 }
268+ if (isLicenseId ) {
269+ LicenseJson license = fetchLicenseJson (licenseIds .get (id .toLowerCase ()));
270+ return license .getPropertyValueNames ();
271+ } else if (isExceptionId ) {
272+ ExceptionJson exc = fetchExceptionJson (exceptionIds .get (id .toLowerCase ()));
273+ return exc .getPropertyValueNames ();
274+ } else if (Objects .nonNull (crossRef )) {
275+ return crossRef .getPropertyValueNames ();
276+ } else {
277+ logger .error ("ID " +id +" is not a listed license ID, crossRef ID nor a listed exception ID" );
278+ throw new SpdxIdNotFoundException ("ID " +id +" is not a listed license ID. crossRef ID nor a listed exception ID" );
279+ }
263280 } finally {
264281 listedLicenseModificationLock .readLock ().unlock ();
265282 }
266- if (isLicenseId ) {
267- LicenseJson license = fetchLicenseJson (licenseIds .get (id .toLowerCase ()));
268- return license .getPropertyValueNames ();
269- } else if (isExceptionId ) {
270- ExceptionJson exc = fetchExceptionJson (exceptionIds .get (id .toLowerCase ()));
271- return exc .getPropertyValueNames ();
272- } else if (Objects .nonNull (crossRef )) {
273- return crossRef .getPropertyValueNames ();
274- } else {
275- logger .error ("ID " +id +" is not a listed license ID, crossRef ID nor a listed exception ID" );
276- throw new SpdxIdNotFoundException ("ID " +id +" is not a listed license ID. crossRef ID nor a listed exception ID" );
277- }
278283 }
279284
280285 /**
@@ -322,10 +327,10 @@ private LicenseJson fetchLicenseJson(String idCaseInsensitive) throws InvalidSPD
322327 this .listedLicenseCache .put (id , license );
323328 } catch (MalformedURLException e ) {
324329 logger .error ("Json license invalid for ID " +id );
325- throw ( new SpdxListedLicenseException ("JSON license URL invalid for ID " +id ) );
330+ throw new SpdxListedLicenseException ("JSON license URL invalid for ID " +id );
326331 } catch (IOException e ) {
327332 logger .error ("I/O error opening Json license URL" );
328- throw ( new SpdxListedLicenseException ("I/O Error reading license data for ID " +id ) );
333+ throw new SpdxListedLicenseException ("I/O Error reading license data for ID " +id );
329334 } finally {
330335 if (reader != null ) {
331336 try {
@@ -393,10 +398,10 @@ private ExceptionJson fetchExceptionJson(String idCaseInsensitive) throws Invali
393398 this .listedExceptionCache .put (id , exc );
394399 } catch (MalformedURLException e ) {
395400 logger .error ("Json license invalid for ID " +id );
396- throw ( new SpdxListedLicenseException ("JSON license URL invalid for ID " +id ) );
401+ throw new SpdxListedLicenseException ("JSON license URL invalid for ID " +id );
397402 } catch (IOException e ) {
398403 logger .error ("I/O error opening Json license URL" );
399- throw ( new SpdxListedLicenseException ("I/O Error reading license data for ID " +id ) );
404+ throw new SpdxListedLicenseException ("I/O Error reading license data for ID " +id );
400405 } finally {
401406 if (reader != null ) {
402407 try {
@@ -663,8 +668,8 @@ public Object next() {
663668 throw new RuntimeException (new InvalidSPDXAnalysisException ("Invalid type for " +propertyName +". Must be of type CrossRefJson" ));
664669 }
665670 CrossRefJson nextCrossRef = (CrossRefJson )nextVal ;
666- listedLicenseModificationLock .writeLock ().lock ();
667671 String crossRefId = nextCrossRef .getId ();
672+ listedLicenseModificationLock .writeLock ().lock ();
668673 try {
669674 if (Objects .isNull (crossRefId )) {
670675 // Need to create an ID and store it in the cache
@@ -977,7 +982,7 @@ public boolean collectionContains(String documentUri, String id, String property
977982 if (isLicenseId ) {
978983 LicenseJson license = fetchLicenseJson (id );
979984 List <Object > valueList = (List <Object >)(List <?>)license .getValueList (propertyName );
980- if (value instanceof TypedValue && ( SpdxConstants .CLASS_CROSS_REF .equals (((TypedValue )value ).getType () ))) {
985+ if (value instanceof TypedValue && SpdxConstants .CLASS_CROSS_REF .equals (((TypedValue )value ).getType ())) {
981986 CrossRefJson compareValue = crossRefs .get (((TypedValue )value ).getId ());
982987 if (Objects .isNull (compareValue )) {
983988 return false ;
@@ -1179,7 +1184,7 @@ public void delete(String documentUri, String id) throws InvalidSPDXAnalysisExce
11791184 throw new SpdxIdNotFoundException ("Document URI for SPDX listed licenses is expected to be " +
11801185 SpdxConstants .LISTED_LICENSE_URL + ". Supplied document URI was " +documentUri );
11811186 }
1182- listedLicenseModificationLock .writeLock ().lock ();;
1187+ listedLicenseModificationLock .writeLock ().lock ();
11831188 try {
11841189 if (licenseIds .containsKey (id .toLowerCase ())) {
11851190 this .listedLicenseCache .remove (id );
0 commit comments