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

Fixes potential StringIndexOutOfBoundsException in Java parser #5003

Merged
merged 14 commits into from
Feb 10, 2025

Conversation

knutwannheden
Copy link
Contributor

java.lang.StringIndexOutOfBoundsException: begin 1495, end 1475, length 3807
  java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
  java.base/java.lang.String.substring(String.java:2709)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitAnnotation(ReloadableJava17ParserVisitor.java:151)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitAnnotation(ReloadableJava17ParserVisitor.java:77)
  com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2921)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1746)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.sortedModifiersAndAnnotations(ReloadableJava17ParserVisitor.java:2187)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariables(ReloadableJava17ParserVisitor.java:1593)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariable(ReloadableJava17ParserVisitor.java:1583)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariable(ReloadableJava17ParserVisitor.java:77)
  com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1045)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1746)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1797)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1790)
  ...

```
java.lang.StringIndexOutOfBoundsException: begin 1495, end 1475, length 3807
  java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
  java.base/java.lang.String.substring(String.java:2709)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitAnnotation(ReloadableJava17ParserVisitor.java:151)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitAnnotation(ReloadableJava17ParserVisitor.java:77)
  com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2921)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1746)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.sortedModifiersAndAnnotations(ReloadableJava17ParserVisitor.java:2187)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariables(ReloadableJava17ParserVisitor.java:1593)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariable(ReloadableJava17ParserVisitor.java:1583)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.visitVariable(ReloadableJava17ParserVisitor.java:77)
  com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1045)
  com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:86)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1746)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1797)
  org.openrewrite.java.isolated.ReloadableJava17ParserVisitor.convert(ReloadableJava17ParserVisitor.java:1790)
  ...
```
@knutwannheden
Copy link
Contributor Author

Still as a draft, as we would have to adjust all Java parser visitors, if we want to proceed with this.

@jevanlingen jevanlingen self-assigned this Feb 10, 2025
@jevanlingen jevanlingen marked this pull request as ready for review February 10, 2025 12:50
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-hcl/src/main/java/org/openrewrite/hcl/format/TabsAndIndentsVisitor.java
    • lines 255-256
  • rewrite-hcl/src/main/java/org/openrewrite/hcl/internal/HclPrinter.java
    • lines 363-364
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/AnnotationTemplateGenerator.java
    • lines 158-159
  • rewrite-java/src/main/java/org/openrewrite/java/internal/template/BlockStatementTemplateGenerator.java
    • lines 281-282
    • lines 669-669
  • rewrite-java/src/main/java/org/openrewrite/java/search/FindEmptyClasses.java
    • lines 57-57
  • rewrite-xml/src/main/java/org/openrewrite/xml/internal/XmlPrinter.java
    • lines 106-106
  • rewrite-yaml/src/main/java/org/openrewrite/yaml/cleanup/RemoveUnusedVisitor.java
    • lines 76-76

@timtebeek timtebeek added the bug Something isn't working label Feb 10, 2025
Copy link
Contributor Author

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

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

LGTM.

@jevanlingen jevanlingen merged commit c50c746 into main Feb 10, 2025
0 of 2 checks passed
@jevanlingen jevanlingen deleted the fix-visitAnnotation-NPE branch February 10, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants