Skip to content

Conversation

@douglasclarke
Copy link
Contributor

Current impl reports the failed index on the next token or null if already at last token.
This minor fix corrects the errorLocation based on the token matching incrementing index before failing
Added two test cases to validate with pure text abd var template matches.

if (templateOutputHandler.matches()) {
fail(templateOutputHandler.getDifferences().getDifferenceMessage());
}
assertEquals(String.format("Normal text of license does not match starting at line #2 column #18 \"zebra\" when comparing to template text \"%s\"", templateText), templateOutputHandler.getDifferences().getDifferenceMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the indexes inside LineColumn, but from this message and numbers 2 (line) and 18 (column) in two assertEquals statements, it looks like the index for Line starts at 1 and the index for Column starts at 0?

(we have one "\n" in the string = 2 lines; and "zebra" will be at column 18 only if "q" is at column 0)

If this is confirmed, may need to documented (in a separate PR) in https://github.com/spdx/spdx-java-core/blob/main/src/main/java/org/spdx/licenseTemplate/LineColumn.java since it is not intuitive.

Copy link
Contributor Author

@douglasclarke douglasclarke Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. My focus was on getting the correct token that failed in the match to help in comparing licenses with templates and diagnosing the failure.

Agree that line is 1 based and column is zero based in LineColumn. Assumed addressing that is a much bigger fix.

I believe this comes from SpdxLicenseTemplateHelper.class in spdx-java-core. We can work-around adding to the column value when creating the strings but is not ideal dealing with a side-effect that could change in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go ahead and merge this PR in for the release - we can create a separate issue / PR to address the line numbering issue.

@goneall goneall merged commit 15a7461 into spdx:master Apr 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants