Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions hadoop-hdds/common/dev-support/findbugsExcludeFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
</Match>

<!-- Test -->
<Match>
<Class name="org.apache.hadoop.hdds.TestHddsUtils"></Class>
<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME" />
</Match>
<Match>
<Class name="~org\.apache\.hadoop\.hdds\.scm\.net\.TestNodeSchemaLoader\$.*"></Class>
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Other suppressions can be also removed. I guess they must have been resolved earlier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should this file be removed if those filters are fixed?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, because the suppressions above <!-- Test --> are still needed.

Copy link
Contributor

@adoroszlai adoroszlai Feb 23, 2025

Choose a reason for hiding this comment

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

Sorry, I omitted "test" from my first comment... It should have been "Other test suppressions".

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ void testGetHostName() {

@Test
void validatePath() {
HddsUtils.validatePath(Paths.get("/"), Paths.get("/"));
HddsUtils.validatePath(Paths.get("/a"), Paths.get("/"));
HddsUtils.validatePath(Paths.get("/a"), Paths.get("/a"));
HddsUtils.validatePath(Paths.get("/a/b"), Paths.get("/a"));
HddsUtils.validatePath(Paths.get("/a/b/c"), Paths.get("/a"));
HddsUtils.validatePath(Paths.get("/a/../a/b"), Paths.get("/a"));
HddsUtils.validatePath(Paths.get("root"), Paths.get("root"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of changing the test paths, we can parameterize the test case. This is enough for findbugs to stop complaining, and also improves the code (which was added before we started using JUnit5).

  static List<Arguments> validPaths() {
    return Arrays.asList(
        Arguments.of("/", "/"),
        ...

  @ParameterizedTest
  @MethodSource("validPaths")
  void validatePathAcceptsValidPath(String path, String ancestor) {
    HddsUtils.validatePath(Paths.get(path), Paths.get(ancestor));
  }

  static List<Arguments> invalidPaths() {
    return Arrays.asList(
        Arguments.of("/b/c", "/a"),
        ...

  @ParameterizedTest
  @MethodSource("invalidPaths")
  void validatePathRejectsInvalidPath(String path, String ancestor) {
    assertThrows(IllegalArgumentException.class,
        () -> HddsUtils.validatePath(Paths.get(path), Paths.get(ancestor)));
  }

HddsUtils.validatePath(Paths.get("root/a"), Paths.get("root"));
HddsUtils.validatePath(Paths.get("root/a"), Paths.get("root/a"));
HddsUtils.validatePath(Paths.get("root/a/b"), Paths.get("root/a"));
HddsUtils.validatePath(Paths.get("root/a/b/c"), Paths.get("root/a"));
HddsUtils.validatePath(Paths.get("root/a/../a/b"), Paths.get("root/a"));

assertThrows(IllegalArgumentException.class,
() -> HddsUtils.validatePath(Paths.get("/b/c"), Paths.get("/a")));
() -> HddsUtils.validatePath(Paths.get("root/b/c"), Paths.get("root/a")));
assertThrows(IllegalArgumentException.class,
() -> HddsUtils.validatePath(Paths.get("/"), Paths.get("/a")));
() -> HddsUtils.validatePath(Paths.get("root"), Paths.get("root/a")));
assertThrows(IllegalArgumentException.class,
() -> HddsUtils.validatePath(Paths.get("/a/.."), Paths.get("/a")));
() -> HddsUtils.validatePath(Paths.get("root/a/.."), Paths.get("root/a")));
assertThrows(IllegalArgumentException.class,
() -> HddsUtils.validatePath(Paths.get("/a/../b"), Paths.get("/a")));
() -> HddsUtils.validatePath(Paths.get("root/a/../b"), Paths.get("root/a")));
}

@Test
Expand Down