Skip to content

fix: avoid infinite recursion on imported directories - #15596

Merged
mcollovati merged 2 commits into
vaadin:masterfrom
javier-godoy:fix-15595
Jan 17, 2023
Merged

mcollovati merged 2 commits into
vaadin:masterfrom
javier-godoy:fix-15595

Conversation

@javier-godoy

Copy link
Copy Markdown
Contributor

Close #15595

Description

The check of whether the file has already been visited should be done after converting a directory to directory/index.js by getImportedFrontendFile (#15023). Otherwise, directory would never be found in visitedPath, and it will enter infinite recursion.

if (visitedImports.contains(path)) {
return;
}
File file = getImportedFrontendFile(path);
if (file == null) {
return;
}
Path filePath = file.toPath();
visitedImports.add(filePath.normalize().toString().replace("\\", "/"));

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@CLAassistant

CLAassistant commented Dec 30, 2022 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Artur-

Artur- commented Dec 31, 2022

Copy link
Copy Markdown
Member

Looks good but could use a test

@github-actions

github-actions Bot commented Jan 9, 2023 •

Copy link
Copy Markdown
Contributor

Test Results

   932 files  ±0     932 suites  ±0   51m 14s ⏱️ - 3m 8s
5 846 tests +2  5 810 ✔️ +2  36 💤 ±0  0 ❌ ±0 
6 096 runs   - 2  6 053 ✔️  - 2  43 💤 ±0  0 ❌ ±0 

Results for commit ddc96de. ± Comparison against base commit 32bc751.

♻️ This comment has been updated with latest results.

@MarcinVaadin

Copy link
Copy Markdown
Contributor

@javier-godoy

Looks good but could use a test

@mcollovati mcollovati added the Contribution PRs coming from the community or external to the team label Jan 9, 2023
@mcollovati mcollovati self-assigned this Jan 16, 2023
@mcollovati

Copy link
Copy Markdown
Collaborator

@javier-godoy @Artur- I added a couple of tests and also made a patch for an issue when importing a directory whose index.js in turn has other import statements.
Do you mind taking a look?

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@MarcinVaadin
MarcinVaadin requested a review from Artur- January 16, 2023 12:10

@Artur- Artur- left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't say I fully understand what is happening in the code but it is not because of this PR.

After running one of the tests, the visitedImports set contains

"theme/myTheme/directory/sub1.js"
"/var/folders/3r/3_0g1bhn44j1vvvpfksrz1z40000gn/T/junit17400761833385662199/frontend/src/directory/index.js"
"theme/myTheme/directory"
"/var/folders/3r/3_0g1bhn44j1vvvpfksrz1z40000gn/T/junit17400761833385662199/frontend/src/main-template.js"
"/var/folders/3r/3_0g1bhn44j1vvvpfksrz1z40000gn/T/junit17400761833385662199/frontend/src/directory/sub1.js"

So it is some kind of mix between import strings and absolute paths...

@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @javier-godoy and @mcollovati, when i performed cherry-pick to this commit to 23.3, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick cfa768d
error: could not apply cfa768d... fix: avoid infinite recursion on imported directories (#15596)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @javier-godoy and @mcollovati, when i performed cherry-pick to this commit to 23.2, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick cfa768d
error: could not apply cfa768d... fix: avoid infinite recursion on imported directories (#15596)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@mcollovati

Copy link
Copy Markdown
Collaborator

There are missing cherry-picks of #15005 on 23.2, 9.0 and 2.8 that should be applied before picking this change

tepi pushed a commit that referenced this pull request Jan 18, 2023
Fixes #15595

Co-authored-by: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
mcollovati added a commit that referenced this pull request Jan 20, 2023
Fixes #15595

Co-authored-by: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
mcollovati added a commit that referenced this pull request Jan 20, 2023
Fixes #15595

Co-authored-by: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
tepi pushed a commit that referenced this pull request Jan 24, 2023
Fixes #15595

Co-authored-by: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.0.0.alpha10 and is also targeting the upcoming stable 24.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in build-frontend from 23.2.x to 23.3.x

7 participants