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

Crash writing json files while using multiple root directories #354

Closed
Alberth289346 opened this issue Apr 7, 2022 · 4 comments
Closed
Assignees
Labels
bug Issue/PR that involves a bug report-viewer PR / Issue deals (partly) with the report viewer and thus involves web-dev technologies
Milestone

Comments

@Alberth289346
Copy link
Contributor

The new reporting backend breaks on trying to write to non-existing directories.

# using 2 directories, each containing 1 `merged.cif` file.
$ ls -1 1DH/merged/2018-101/* 1DH/merged/2018-102/*
1DH/merged/2018-101/merged.cif
1DH/merged/2018-102/merged.cif

# Delete all files in result.
$ rm result/*

# 38173b1 without all frontends + our own cif language frontend
$ java -jar cifjplag.jar -bc 1DH/merged/_base 1DH/merged/2018-101 1DH/merged/2018-102 
Initialized language CIF
JPlag initialized
Basecode directory "_base" will be used.
2 submissions parsed successfully!
0 parser errors!
0 too short submissions!

----- Parsing basecode submission: _base
Basecode submission parsed!
Comparing 2018-101/merged.cif-2018-102/merged.cif: 34.77527

Total time for comparing submissions: 0 sec
Failed to save json files: result/2018-101/merged.cif-2018-102/merged.cif.json (No such file or directory)

# ls results
overview.json

Backtracking to cause:

// JsonFactory.java
// line 47
            for (ComparisonReport report : jPlagReport.getComparisons()) {
                String name = report.getFirstSubmissionId().concat("-").concat(report.getSecondSubmissionId()).concat(".json");
                mapper.writeValue(Path.of(folderPath, name).toFile(), report);
            }
        } catch (IOException e) {
            System.out.println("Failed to save json files: " + e.getMessage());
            return false;
        }
// ComparisonReport.java
// line 9
    @JsonProperty("first_submission_id")
    private final String firstSubmissionId;

    @JsonProperty("second_submission_id")
    private final String secondSubmissionId;

// line 27
    public ComparisonReport(String firstSubmissionId, String secondSubmissionId, float matchPercentage,
            List<FilesOfSubmission> filesOfFirstSubmission, List<FilesOfSubmission> filesOfSecondSubmission, List<Match> matches) {

        this.firstSubmissionId = firstSubmissionId;
        this.secondSubmissionId = secondSubmissionId;
// ReportObjectFactory.java
// line 64
                new ComparisonReport(comparison.getFirstSubmission().getName(), //
                        comparison.getSecondSubmission().getName(), //
                        comparison.similarity(), //
                        getFilesForSubmission(comparison.getFirstSubmission()), //
                        getFilesForSubmission(comparison.getSecondSubmission()), //
                        convertMatchesToReportMatches(result, comparison, comparison.getMatches()) //
                )));
// JPlagComparison.java
// line 23
    public JPlagComparison(Submission firstSubmission, Submission secondSubmission) {
        this.firstSubmission = firstSubmission;
        this.secondSubmission = secondSubmission;
        matches = new ArrayList<>();
// SubmissionSetBuilder.java
// line 234
    private Submission processSubmission(String submissionName, File submissionFile) throws ExitException {

// line 250 (also in processSubmission)
        submissionFile = makeCanonical(submissionFile, it -> new SubmissionException("Cannot create submission: " + submissionName, it));
        return new Submission(submissionName, submissionFile, parseFilesRecursively(submissionFile), language, errorCollector);

// line 265 (in processRootDirectoryEntries)
                String rootDirectoryPrefix = multipleRoots ? (rootDirectory.getName() + File.separator) : "";
                String submissionName = rootDirectoryPrefix + fileName;
                Submission submission = processSubmission(submissionName, submissionFile);

That is, as soon as you specify more than one root directory, you get directory separators in the name. Simple name concatenation thus fails.

Note that even without the directory problems, string concatenation will fail, eg submissions named {A, A-B, C, B-C} will result in 2 A-B-C names.

@tsaglam tsaglam added the bug Issue/PR that involves a bug label Apr 7, 2022
@tsaglam tsaglam added this to the v4.0.0 milestone Apr 7, 2022
@sebinside sebinside added the report-viewer PR / Issue deals (partly) with the report viewer and thus involves web-dev technologies label Apr 7, 2022
@caemor
Copy link

caemor commented Jun 20, 2022

Is there an workaround to already use the -new and -oldparameters without getting this bug?

@tsaglam
Copy link
Member

tsaglam commented Jun 20, 2022

Currently, no. But this is being worked on and will be fixed in the v4.0.0 release. If you subscribe to this issue you will be notified whenever this is resolved.

@caemor
Copy link

caemor commented Jun 20, 2022

Thanks for your work and the quick reply!

@tsaglam
Copy link
Member

tsaglam commented Aug 22, 2022

Resolved by #569, if you encounter any further issues, please let us know.
@Alberth289346 @caemor feel free to test the multi-root feature with the new report viewer.

@tsaglam tsaglam closed this as completed Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue/PR that involves a bug report-viewer PR / Issue deals (partly) with the report viewer and thus involves web-dev technologies
Projects
None yet
Development

No branches or pull requests

4 participants