Skip to content

Commit

Permalink
Tolerate weird class names, as seen in functionaljava (#4401)
Browse files Browse the repository at this point in the history
* Tolerate weird class names, as seen in functionaljava

They are using `fj.data.$`, which then leads to an empty String.

* Add test as suggested

* Test in isolation
  • Loading branch information
timtebeek authored Aug 9, 2024
1 parent 3a12433 commit 97f049c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ void gavCoordinateFromMaven() {
assertThat(gavFromPath(Paths.get("C:/Users/Sam/.m2/repository/org/openrewrite/rewrite-core/8.32.0/rewrite-core-8.32.0.jar")))
.isEqualTo("org.openrewrite:rewrite-core:8.32.0");
}

@Test
@Issue("https://github.com/openrewrite/rewrite/pull/4401")
void tolerateWeirdClassNames(){
assertThat(JavaSourceSet.isDeclarable("fj.data.$")).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ private static String entryNameToClassName(String entryName) {
.replace('/', '.');
}

private static boolean isDeclarable(String className) {
static boolean isDeclarable(String className) {
int dotIndex = Math.max(className.lastIndexOf("."), className.lastIndexOf('$'));
className = className.substring(dotIndex + 1);
char firstChar = className.charAt(0);
return Character.isJavaIdentifierPart(firstChar) && !Character.isDigit(firstChar);
return !className.isEmpty() &&
Character.isJavaIdentifierPart(className.charAt(0)) &&
!Character.isDigit(className.charAt(0));
}
}

0 comments on commit 97f049c

Please sign in to comment.