Skip to content

Inconsistent behavior when reading filesAnalyzed of a package that does not define it explicitly #142

@nicoweidner

Description

@nicoweidner

I ran into a super dubious lazy-loading issue (supposedly), related to reading filesAnalyzed from a document deserialized from a json file that did not set this property.

I tried to verify that conversion from tag/value to json using the Python tools does not change any properties. To that end, I wrote a simple test in spdx-testbed:

  @Test
  public void detectDifferences()
      throws IOException, InvalidFileNameException, InvalidSPDXAnalysisException {
    var convertedFile = SpdxToolsHelper.deserializeDocument(new File("converted.json"));
    var originalFile = SpdxToolsHelper.deserializeDocument(new File("SPDXTagExample-v2.2.spdx"));
    var differences = Comparisons.findDifferencesInSerializedJson(convertedFile, originalFile);
    assertThat(differences).isEmpty();
  }

This test failed, because filesAnalyzed was set to true for the document deserialized from tag/value (named originalFile here), while it was unspecified for the document deserialized from json (named convertedFile).

I first suspected that the json reader does not set the default of true while the tag/value reader does.
This may be one issue, but I ran into something weirder: When setting a breakpoint on the var differences = ... line and evaluating the package in question via

convertedFile.getModelStore().getTypedValue(convertedFile.getDocumentUri(), "SPDXRef-Package")

, the filesAnalyzed value actually came back as true, and the test subsequently passed. This feels like some strange lazy-loading issue, but I can't debug anymore because it stopped behaving like this; I can't reproduce this behavior anymore and the test now consistently fails on my machine.

So...

  • filesAnalyzed should probably be set to true as default, like the spec says
  • I am utterly flabberghasted regarding the lazy loading issue

For completeness sake, this is the json file that I used. It was created by converting the 2.2 tag/value example for spdx-spec to json using the Python tools. I think most of it is irrelevant though, the important part is that it contains a package glibc which does not have a value for filesAnalyzed.
converted.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions