Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null before access to creation info / license info #175

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 3 additions & 4 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 @@ -95,9 +94,9 @@ public static void main(String[] args) {
System.exit(ERROR_STATUS);
}
// separate out the warning from errors
List<String> warnings = new ArrayList<>();
List<String> errors = new ArrayList<>();
for (String verifyMsg:verify) {
List<String> warnings = new ArrayList<String>();
bact marked this conversation as resolved.
Show resolved Hide resolved
List<String> errors = new ArrayList<String>();
bact marked this conversation as resolved.
Show resolved Hide resolved
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
Loading