Skip to content

Commit

Permalink
Merge pull request #175 from bact/handle-null
Browse files Browse the repository at this point in the history
Handle null before access to creation info / license info
  • Loading branch information
goneall authored Dec 17, 2024
2 parents 180ac2e + ee88fc7 commit e190384
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/spdx/tools/MatchingStandardLicenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void main(String[] args) {
usage();
System.exit(ERROR_STATUS);
}
@SuppressWarnings("null")
File textFile = new File(args[0]);

if (!textFile.exists()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/spdx/tools/Verify.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static void main(String[] args) {
fileType = SpdxToolsHelper.fileToFileType(new File(args[0]));
}
verify = verify(args[0], fileType);

} catch (SpdxVerificationException e) {
System.out.println(e.getMessage());
System.exit(ERROR_STATUS);
Expand All @@ -97,7 +96,7 @@ public static void main(String[] args) {
// separate out the warning from errors
List<String> warnings = new ArrayList<>();
List<String> errors = new ArrayList<>();
for (String verifyMsg:verify) {
for (String verifyMsg : verify) {
if (verifyMsg.contains(" is deprecated.")) {
warnings.add(verifyMsg);
} else {
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/org/spdx/tools/compare/CreatorSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.SpdxCreatorInformation;
import org.spdx.utility.compare.SpdxCompareException;
import org.spdx.utility.compare.SpdxComparer;

Expand Down Expand Up @@ -90,17 +91,20 @@ public void importCompareResults(SpdxComparer comparer, List<String> docNames) t
for (int i = 0; i < comparer.getNumSpdxDocs(); i++) {
Cell headerCell = header.getCell(i);
headerCell.setCellValue(docNames.get(i));
String[] creators = comparer.getSpdxDoc(i).getCreationInfo().getCreators().toArray(new String[comparer.getSpdxDoc(i).getCreationInfo().getCreators().size()]);
Arrays.sort(creators);
for (int j = 0; j < creators.length; j++) {
Cell creatorCell = null;
while (j+1 > this.getNumDataRows()) {
this.addRow();
SpdxCreatorInformation creationInfo = comparer.getSpdxDoc(i).getCreationInfo();
if (creationInfo != null) {
String[] creators = creationInfo.getCreators().toArray(new String[creationInfo.getCreators().size()]);
Arrays.sort(creators);
for (int j = 0; j < creators.length; j++) {
Cell creatorCell = null;
while (j+1 > this.getNumDataRows()) {
this.addRow();
}
creatorCell = sheet.getRow(j+1).createCell(i);
creatorCell.setCellValue(creators[j]);
}
creatorCell = sheet.getRow(j+1).createCell(i);
creatorCell.setCellValue(creators[j]);
}
}
}

}
}
27 changes: 18 additions & 9 deletions src/main/java/org/spdx/tools/compare/DocumentSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.spdx.core.InvalidSPDXAnalysisException;
import org.spdx.library.model.v2.SpdxCreatorInformation;
import org.spdx.utility.compare.SpdxCompareException;
import org.spdx.utility.compare.SpdxComparer;

/**
* Sheet to hold compare information at the docment level:
* Sheet to hold compare information at the document level:
* Created, Data License, Document Comment
* The first row summarizes which fields are different, the subsequent rows are the
* specific date from each result
Expand Down Expand Up @@ -254,9 +255,12 @@ private void importLicenseListVersions(SpdxComparer comparer) throws SpdxCompare
// data rows
for (int i = 0; i < comparer.getNumSpdxDocs(); i++) {
cell = sheet.getRow(getFirstDataRow()+i+1).createCell(LICENSE_LIST_VERSION_COL);
Optional<String> licenseListVersion = comparer.getSpdxDoc(i).getCreationInfo().getLicenseListVersion();
if (licenseListVersion.isPresent()) {
cell.setCellValue(licenseListVersion.get());
SpdxCreatorInformation creationInfo = comparer.getSpdxDoc(i).getCreationInfo();
if (creationInfo != null) {
Optional<String> licenseListVersion = creationInfo.getLicenseListVersion();
if (licenseListVersion.isPresent()) {
cell.setCellValue(licenseListVersion.get());
}
}
}
}
Expand Down Expand Up @@ -340,11 +344,13 @@ private void importCreatorComment(SpdxComparer comparer) throws InvalidSPDXAnaly
// data rows
for (int i = 0; i < comparer.getNumSpdxDocs(); i++) {
cell = sheet.getRow(getFirstDataRow()+i+1).createCell(CREATOR_COMMENT_COL);
Optional<String> creatorComment = comparer.getSpdxDoc(i).getCreationInfo().getComment();
if (creatorComment.isPresent()) {
cell.setCellValue(creatorComment.get());
SpdxCreatorInformation creationInfo = comparer.getSpdxDoc(i).getCreationInfo();
if (creationInfo != null) {
Optional<String> creatorComment = creationInfo.getComment();
if (creatorComment.isPresent()) {
cell.setCellValue(creatorComment.get());
}
}

}
}

Expand All @@ -364,7 +370,10 @@ private void importCreationDate(SpdxComparer comparer) throws InvalidSPDXAnalysi
// data rows
for (int i = 0; i < comparer.getNumSpdxDocs(); i++) {
cell = sheet.getRow(getFirstDataRow()+i+1).createCell(CREATION_DATE_COL);
cell.setCellValue(comparer.getSpdxDoc(i).getCreationInfo().getCreated());
SpdxCreatorInformation creationInfo = comparer.getSpdxDoc(i).getCreationInfo();
if (creationInfo != null) {
cell.setCellValue(creationInfo.getCreated());
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/spdx/tools/compare/PackageSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.spdx.library.model.v2.SpdxDocument;
import org.spdx.library.model.v2.SpdxPackage;
import org.spdx.library.model.v2.SpdxPackageVerificationCode;
import org.spdx.library.model.v2.license.AnyLicenseInfo;
import org.spdx.utility.compare.SpdxCompareException;
import org.spdx.utility.compare.SpdxComparer;
import org.spdx.utility.compare.SpdxPackageComparer;
Expand Down Expand Up @@ -404,7 +405,10 @@ private void addPackageToSheet(SpdxPackageComparer comparer,
}
concludedLicenseRow.createCell(FIRST_DOC_COL+i).setCellValue(pkg.getLicenseConcluded().toString());
licenseInfosFromFilesRow.createCell(FIRST_DOC_COL+i).setCellValue(CompareHelper.licenseInfosToString(pkg.getLicenseInfoFromFiles()));
declaredLicenseRow.createCell(FIRST_DOC_COL+i).setCellValue(pkg.getLicenseDeclared().toString());
AnyLicenseInfo licenseDeclared = pkg.getLicenseDeclared();
if (licenseDeclared != null) {
declaredLicenseRow.createCell(FIRST_DOC_COL+i).setCellValue(licenseDeclared.toString());
}
Optional<String> licenseComments = pkg.getLicenseComments();
if (licenseComments.isPresent()) {
licenseCommentRow.createCell(FIRST_DOC_COL+i).setCellValue(licenseComments.get());
Expand Down
2 changes: 1 addition & 1 deletion testResources/sourcefiles/DocumentSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.spdx.utility.compare.SpdxComparer;

/**
* Sheet to hold compare information at the docment level:
* Sheet to hold compare information at the document level:
* Created, Data License, Document Comment
* The first row summarizes which fields are different, the subsequent rows are the
* specific date from each result
Expand Down

0 comments on commit e190384

Please sign in to comment.