rewrite-java-security icon indicating copy to clipboard operation
rewrite-java-security copied to clipboard

Control flow can not generate fake conditional when the for each iterable is of type J$Ternary

Open JLLeitschuh opened this issue 2 years ago • 0 comments

Problem

Describe the issue you are experiencing.

Expected behavior

Describe what you expected to see.

Example diff

                                 + "{ this(" + (dim > 0 ? "Math.min(firstValue.length, secondValue.length)" : "") + "); put(firstValue, secondValue); }\n";
                   }
               } else if (resizable && firstType == null && secondType == null) {
-                    for (String javaName : valueType.javaNames != null ? valueType.javaNames : new String[]{valueType.javaName}) {
+                    /*~~(java.lang.ClassCastException: class org.openrewrite.java.tree.J$Ternary cannot be cast to class org.openrewrite.java.tree.J$MethodInvocation (org.openrewrite.java.tree.J$Ternary and org.openrewrite.java.tree.J$MethodInvocation are in unnamed module of loader 'app')
+  org.openrewrite.java.controlflow.ControlFlow$ControlFlowAnalysis.createFakeConditionalMethod(ControlFlow.java:623)
+  org.openrewrite.java.controlflow.ControlFlow$ControlFlowAnalysis.visitForEachLoop(ControlFlow.java:603)
+  org.openrewrite.java.controlflow.ControlFlow$ControlFlowAnalysis.visitForEachLoop(ControlFlow.java:90)
+  org.openrewrite.java.tree.J$ForEachLoop.acceptJava(J.java:1862)
+  org.openrewrite.java.tree.J.accept(J.java:60)
+  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:206)
+  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:145)
+  org.openrewrite.java.controlflow.ControlFlow$ControlFlowAnalysis.visitRecursive(ControlFlow.java:171)
+  ...)~~>*/for (String javaName : valueType.javaNames != null ? valueType.javaNames : new String[]{valueType.javaName}) {
                       if (dim < 2 && !javaName.equals("int") && !javaName.equals("long")) {
                           decl.text += "    public " + containerType.javaName + "(" + javaName + " value) { this(1); put(0, value); }\n";
                       }

Recipes in example diff:

  • org.openrewrite.java.security.PartialPathTraversalVulnerability

References:

  • Recipe ID: undefined
  • Recipe Name: "Partial path traversal vulnerability"
  • Repository: wumo/gradle-javacpp-plugin/master
  • Created at Thu Sep 08 2022 22:52:42 GMT-0400 (Eastern Daylight Time)

JLLeitschuh avatar Sep 09 '22 02:09 JLLeitschuh