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

Issue #13809: Kill mutation in CommonUtil #13953

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

Kevin222004
Copy link
Contributor

@Kevin222004 Kevin222004 commented Oct 26, 2023

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items :

@@ -261,8 +261,8 @@ public static String relativizeAndNormalizePath(final String baseDirectory, fina
resultPath = path;
}
else {
final Path pathAbsolute = Paths.get(path).normalize();
final Path pathBase = Paths.get(baseDirectory).normalize();
final Path pathAbsolute = Paths.get(path);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we need to test message of violation and validate how path is starting https://www.google.com/amp/s/www.geeksforgeeks.org/path-normalize-method-in-java-with-examples/amp/

To be OS agnostic we usually avoid checking full path in violation, we might do only file name

Copy link
Member

Choose a reason for hiding this comment

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

What we can test is ... We set path with . and/or .. but have in violation path without such symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried multiple ways but at the i didn't find a way in which relativize path is getting affected.

Copy link
Member

Choose a reason for hiding this comment

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

yes, such normalization is done by jdk
https://github.com/openjdk/jdk/blob/db3402577a2c14a41045753a1ffe2829a6bdda91/src/java.base/unix/classes/sun/nio/fs/UnixPath.java#L478-L495

we already have test on this

public void testRelativeNormalizedPathWithDenormalizedBaseDirectory() throws IOException {
final String sampleAbsolutePath = new File("src/main/java").getCanonicalPath();
final String absoluteFilePath = sampleAbsolutePath + "/SampleFile.java";
final String basePath = sampleAbsolutePath + PATH_DENORMALIZER;

Copy link
Member

@romani romani Oct 29, 2023

Choose a reason for hiding this comment

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

We do not need to care about path in zips and JrtPath is something I do not understand.
image

Copy link
Member

Choose a reason for hiding this comment

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

We do not need to care about path in zips

You may want to recheck this. Some users put configuration files into external JARs controlled by Maven. Those are basically ZIP files.

Copy link
Member

@romani romani Oct 30, 2023

Choose a reason for hiding this comment

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

We will happily fix issue if they will show how to reproduce issue.

It will be easy, revert with already known input how to reproduce it.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

ok to merge

@rnveach
Copy link
Member

rnveach commented Oct 29, 2023

  1. Where is regression showing this won't be an issue? This is used by Checker.
  2. This method is not really called "relativizeAndNormalizePath" if there is no more normalize.

@romani
Copy link
Member

romani commented Oct 29, 2023

Where is regression showing this won't be an issue? This is used by Checker.

regression is only covering behavior on config, to make this regression something weird should be done with paths to validate. non of our tools can do this.

This method is not really called "relativizeAndNormalizePath" if there is no more normalize.

jdk relativize does normalize internaly. Do you propose to change name of util method ?

@rnveach
Copy link
Member

rnveach commented Oct 29, 2023

Regression should also cover file paths which is done by Checker, as 2 paths need to line up for a match for differencing. If it truthfully has no impact, regression will show no differences either way and will show we won't have anything to worry about after merge.

I am leaning to changing the util name and javadoc since I assume it was named normalize for the normalize that happened in it.

@romani
Copy link
Member

romani commented Oct 29, 2023

method is renamed.

@romani
Copy link
Member

romani commented Oct 29, 2023

Github, generate report

@github-actions
Copy link
Contributor

@romani
Copy link
Member

romani commented Oct 29, 2023

@rnveach , please review.

@rnveach
Copy link
Member

rnveach commented Oct 29, 2023

@romani Please make sure you are using a config to hit the code. baseDir has to be set to trigger the changed code as shown in the method in this pr.

if (baseDirectory == null) {
resultPath = path;
}
else {
final Path pathAbsolute = Paths.get(path).normalize();
final Path pathBase = Paths.get(baseDirectory).normalize();

@romani
Copy link
Member

romani commented Oct 30, 2023

Github, generate report

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2023

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/6687338433

https://github.com/checkstyle/checkstyle/actions/runs/6687338433/job/18167872017#step:9:578

Caused by: java.lang.IllegalArgumentException: 'other' is different type of Path
    at sun.nio.fs.UnixPath.relativize (UnixPath.java:429)
    at sun.nio.fs.UnixPath.relativize (UnixPath.java:43)
    at com.puppycrawl.tools.checkstyle.utils.CommonUtil.relativizeAndNormalizePath (CommonUtil.java:266)
    at com.puppycrawl.tools.checkstyle.Checker.acceptFileStarted (Checker.java:377)
    at com.puppycrawl.tools.checkstyle.Checker.processFiles (Checker.java:291)
    at com.puppycrawl.tools.checkstyle.Checker.process (Checker.java:226)

https://github.com/openjdk/jdk/blob/db3402577a2c14a41045753a1ffe2829a6bdda91/src/java.base/unix/classes/sun/nio/fs/UnixPath.java#L478-L495

    public UnixPath relativize(Path obj) {
        UnixPath child = toUnixPath(obj);
        if (child.equals(this))
            return emptyPath();

        // can only relativize paths of the same type
        if (this.isAbsolute() != child.isAbsolute())
            throw new IllegalArgumentException("'other' is different type of Path");

Copy link
Contributor

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

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

lgtm

normalization is done as part of relativize for UnixPath

@romani
Copy link
Member

romani commented Oct 31, 2023

regression report needs to pass, I am not sure why it is failing with exception.

@Kevin222004
Copy link
Contributor Author

Github, generate report

Copy link
Contributor

github-actions bot commented Nov 5, 2023

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/6763272802

@Vyom-Yadav
Copy link
Member

@romani @Kevin222004 I think there is a problem with relativizing path.

Caused by: java.lang.IllegalArgumentException: 'other' is different type of Path
    at sun.nio.fs.UnixPath.relativize (UnixPath.java:429)
    at sun.nio.fs.UnixPath.relativize (UnixPath.java:43)
    at com.puppycrawl.tools.checkstyle.utils.CommonUtil.relativizeAndNormalizePath (CommonUtil.java:266)

You may want to take a look at https://stackoverflow.com/q/16299604/15412365

@romani
Copy link
Member

romani commented Nov 7, 2023

problem is at relativizeAndNormalizePath , so it is execution without update of this PR.
so exception is not related to PR update, and this is just bad config.

config is updated:

- <property name="basedir" value="."/>
+ <property name="basedir" value="/work/checkstyle/checkstyle/.ci-temp/contribution/checkstyle-tester/"/>

@romani
Copy link
Member

romani commented Nov 7, 2023

Github, generate report

1 similar comment
@romani
Copy link
Member

romani commented Nov 8, 2023

Github, generate report

Copy link
Contributor

github-actions bot commented Nov 8, 2023

@romani
Copy link
Member

romani commented Nov 8, 2023

@rnveach , report is ready.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Ok to merge

@romani romani removed their assignment Nov 8, 2023
@rnveach
Copy link
Member

rnveach commented Nov 8, 2023

@romani So we are not going to do anything on #13953 (comment) ?

@romani
Copy link
Member

romani commented Nov 8, 2023

@rnveach , yes, let's have regression if it's actually matters, I will learn a lot from such usage :).
I don't know how to deal with such path in zip for checkstyle.

@rnveach rnveach assigned nrmancuso and unassigned rnveach Nov 12, 2023
@nrmancuso nrmancuso merged commit d52eb5d into checkstyle:master Nov 12, 2023
112 checks passed
@rnveach
Copy link
Member

rnveach commented Nov 14, 2023

Apparently this change failed in backport (JDK 8). Nothing changed in the javadoc for Path.relativize.

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.

None yet

6 participants