소스 검색

Tidy up painless exception strings (#91748)

Compress exception messages spread out over lots of lines
Simon Cooper 2 년 전
부모
커밋
53e500db53

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 267 - 482
modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupBuilder.java


+ 3 - 2
modules/lang-painless/src/main/java/org/elasticsearch/painless/lookup/PainlessLookupUtility.java

@@ -340,11 +340,12 @@ public final class PainlessLookupUtility {
      * derived from an {@link org.elasticsearch.painless.spi.annotation.InjectConstantAnnotation}.
      */
     public static Object[] buildInjections(PainlessMethod painlessMethod, Map<String, Object> constants) {
-        if (painlessMethod.annotations().containsKey(InjectConstantAnnotation.class) == false) {
+        InjectConstantAnnotation injects = (InjectConstantAnnotation) painlessMethod.annotations().get(InjectConstantAnnotation.class);
+        if (injects == null) {
             return new Object[0];
         }
 
-        List<String> names = ((InjectConstantAnnotation) painlessMethod.annotations().get(InjectConstantAnnotation.class)).injects();
+        List<String> names = injects.injects();
         Object[] injections = new Object[names.size()];
 
         for (int i = 0; i < names.size(); i++) {

+ 134 - 271
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultConstantFoldingOptimizationPhase.java

@@ -8,6 +8,7 @@
 
 package org.elasticsearch.painless.phase;
 
+import org.elasticsearch.core.Strings;
 import org.elasticsearch.painless.AnalyzerCaster;
 import org.elasticsearch.painless.Operation;
 import org.elasticsearch.painless.ir.BinaryMathNode;
@@ -45,6 +46,42 @@ import java.util.function.Consumer;
  */
 public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyingVisitor {
 
+    private static IllegalStateException unaryError(String type, String operation, String constant) {
+        return new IllegalStateException(
+            Strings.format(
+                "constant folding error: unexpected type [%s] for unary operation [%s] on constant [%s]",
+                type,
+                operation,
+                constant
+            )
+        );
+    }
+
+    private static IllegalStateException binaryError(String type, String operation, String constant1, String constant2) {
+        return error(type, "binary", operation, constant1, constant2);
+    }
+
+    private static IllegalStateException booleanError(String type, String operation, String constant1, String constant2) {
+        return error(type, "boolean", operation, constant1, constant2);
+    }
+
+    private static IllegalStateException comparisonError(String type, String operation, String constant1, String constant2) {
+        return error(type, "comparison", operation, constant1, constant2);
+    }
+
+    private static IllegalStateException error(String type, String opType, String operation, String constant1, String constant2) {
+        return new IllegalStateException(
+            Strings.format(
+                "constant folding error: unexpected type [%s] for %s operation [%s] on constants [%s] and [%s]",
+                type,
+                opType,
+                operation,
+                constant1,
+                constant2
+            )
+        );
+    }
+
     @Override
     public void visitUnaryMath(UnaryMathNode irUnaryMathNode, Consumer<ExpressionNode> scope) {
         irUnaryMathNode.getChildNode().visit(this, irUnaryMathNode::setChildNode);
@@ -67,17 +104,10 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irUnaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "unary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constant ["
-                                    + irConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            unaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -91,17 +121,10 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irUnaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "unary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constant ["
-                                    + irConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            unaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -113,17 +136,10 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irUnaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "unary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constant ["
-                                    + irConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            unaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -160,20 +176,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -192,20 +199,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irBinaryMathNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "binary operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                binaryError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }
@@ -227,20 +225,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irBinaryMathNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "binary operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                binaryError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }
@@ -261,20 +250,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -292,20 +272,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -319,20 +290,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -346,20 +308,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -373,20 +326,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] and "
-                                    + "["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -400,20 +344,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -429,20 +364,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] and "
-                                    + "["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -456,20 +382,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBinaryMathNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -550,20 +467,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBooleanNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "binary operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            binaryError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -580,20 +488,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                 } else {
                     throw irBooleanNode.getLocation()
                         .createError(
-                            new IllegalStateException(
-                                "constant folding error: "
-                                    + "unexpected type ["
-                                    + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                    + "] for "
-                                    + "boolean operation ["
-                                    + operation.symbol
-                                    + "] on "
-                                    + "constants ["
-                                    + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                    + "] "
-                                    + "and ["
-                                    + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                    + "]"
+                            booleanError(
+                                PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                operation.symbol,
+                                irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                irRightConstantNode.getDecorationString(IRDConstant.class)
                             )
                         );
                 }
@@ -687,20 +586,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irComparisonNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "comparison operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                comparisonError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }
@@ -719,20 +609,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irComparisonNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "comparison operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                comparisonError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }
@@ -751,20 +632,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irComparisonNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "comparison operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                comparisonError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }
@@ -783,20 +655,11 @@ public class DefaultConstantFoldingOptimizationPhase extends IRExpressionModifyi
                     } else {
                         throw irComparisonNode.getLocation()
                             .createError(
-                                new IllegalStateException(
-                                    "constant folding error: "
-                                        + "unexpected type ["
-                                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                                        + "] for "
-                                        + "comparison operation ["
-                                        + operation.symbol
-                                        + "] on "
-                                        + "constants ["
-                                        + irLeftConstantNode.getDecorationString(IRDConstant.class)
-                                        + "] "
-                                        + "and ["
-                                        + irRightConstantNode.getDecorationString(IRDConstant.class)
-                                        + "]"
+                                comparisonError(
+                                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                                    operation.symbol,
+                                    irLeftConstantNode.getDecorationString(IRDConstant.class),
+                                    irRightConstantNode.getDecorationString(IRDConstant.class)
                                 )
                             );
                     }

+ 41 - 48
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultIRTreeToASMBytesPhase.java

@@ -8,6 +8,7 @@
 
 package org.elasticsearch.painless.phase;
 
+import org.elasticsearch.core.Strings;
 import org.elasticsearch.painless.ClassWriter;
 import org.elasticsearch.painless.DefBootstrap;
 import org.elasticsearch.painless.Location;
@@ -788,12 +789,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                         methodWriter.push(-1L);
                     } else {
                         throw new IllegalStateException(
-                            "unexpected unary math operation ["
-                                + operation
-                                + "] "
-                                + "for type ["
-                                + irUnaryMathNode.getDecorationString(IRDExpressionType.class)
-                                + "]"
+                            Strings.format(
+                                "unexpected unary math operation [%s] for type [%s]",
+                                operation,
+                                irUnaryMathNode.getDecorationString(IRDExpressionType.class)
+                            )
                         );
                     }
 
@@ -813,12 +813,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                 }
             } else {
                 throw new IllegalStateException(
-                    "unexpected unary math operation ["
-                        + operation
-                        + "] "
-                        + "for type ["
-                        + irUnaryMathNode.getDecorationString(IRDExpressionType.class)
-                        + "]"
+                    Strings.format(
+                        "unexpected unary math operation [%s] for type [%s]",
+                        operation,
+                        irUnaryMathNode.getDecorationString(IRDExpressionType.class)
+                    )
                 );
             }
         }
@@ -845,12 +844,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                 methodWriter.invokeVirtual(Type.getType(Matcher.class), WriterConstants.MATCHER_MATCHES);
             } else {
                 throw new IllegalStateException(
-                    "unexpected binary math operation ["
-                        + operation
-                        + "] "
-                        + "for type ["
-                        + irBinaryMathNode.getDecorationString(IRDExpressionType.class)
-                        + "]"
+                    Strings.format(
+                        "unexpected binary math operation [%s] for type [%s]",
+                        operation,
+                        irBinaryMathNode.getDecorationString(IRDExpressionType.class)
+                    )
                 );
             }
         } else {
@@ -973,24 +971,22 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
 
         if (comparisonType == void.class || comparisonType == byte.class || comparisonType == short.class || comparisonType == char.class) {
             throw new IllegalStateException(
-                "unexpected comparison operation ["
-                    + operation
-                    + "] "
-                    + "for type ["
-                    + irComparisonNode.getDecorationString(IRDExpressionType.class)
-                    + "]"
+                Strings.format(
+                    "unexpected comparison operation [%s] for type [%s]",
+                    operation,
+                    irComparisonNode.getDecorationString(IRDExpressionType.class)
+                )
             );
         } else if (comparisonType == boolean.class) {
             if (eq) methodWriter.ifCmp(type, MethodWriter.EQ, jump);
             else if (ne) methodWriter.ifCmp(type, MethodWriter.NE, jump);
             else {
                 throw new IllegalStateException(
-                    "unexpected comparison operation ["
-                        + operation
-                        + "] "
-                        + "for type ["
-                        + irComparisonNode.getDecorationString(IRDExpressionType.class)
-                        + "]"
+                    Strings.format(
+                        "unexpected comparison operation [%s] for type [%s]",
+                        operation,
+                        irComparisonNode.getDecorationString(IRDExpressionType.class)
+                    )
                 );
             }
         } else if (comparisonType == int.class
@@ -1005,12 +1001,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                 else if (gte) methodWriter.ifCmp(type, MethodWriter.GE, jump);
                 else {
                     throw new IllegalStateException(
-                        "unexpected comparison operation ["
-                            + operation
-                            + "] "
-                            + "for type ["
-                            + irComparisonNode.getDecorationString(IRDExpressionType.class)
-                            + "]"
+                        Strings.format(
+                            "unexpected comparison operation [%s] for type [%s]",
+                            operation,
+                            irComparisonNode.getDecorationString(IRDExpressionType.class)
+                        )
                     );
                 }
 
@@ -1054,12 +1049,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                     writejump = false;
                 } else {
                     throw new IllegalStateException(
-                        "unexpected comparison operation ["
-                            + operation
-                            + "] "
-                            + "for type ["
-                            + irComparisonNode.getDecorationString(IRDExpressionType.class)
-                            + "]"
+                        Strings.format(
+                            "unexpected comparison operation [%s] for type [%s]",
+                            operation,
+                            irComparisonNode.getDecorationString(IRDExpressionType.class)
+                        )
                     );
                 }
             } else {
@@ -1083,12 +1077,11 @@ public class DefaultIRTreeToASMBytesPhase implements IRTreeVisitor<WriteScope> {
                     }
                 } else {
                     throw new IllegalStateException(
-                        "unexpected comparison operation ["
-                            + operation
-                            + "] "
-                            + "for type ["
-                            + irComparisonNode.getDecorationString(IRDExpressionType.class)
-                            + "]"
+                        Strings.format(
+                            "unexpected comparison operation [%s] for type [%s]",
+                            operation,
+                            irComparisonNode.getDecorationString(IRDExpressionType.class)
+                        )
                     );
                 }
             }

+ 98 - 140
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultSemanticAnalysisPhase.java

@@ -8,6 +8,7 @@
 
 package org.elasticsearch.painless.phase;
 
+import org.elasticsearch.core.Strings;
 import org.elasticsearch.painless.AnalyzerCaster;
 import org.elasticsearch.painless.CompilerSettings;
 import org.elasticsearch.painless.FunctionRef;
@@ -158,6 +159,10 @@ import static org.elasticsearch.painless.symbol.SemanticScope.newFunctionScope;
  */
 public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticScope> {
 
+    private static ClassCastException castError(String formatText, Object... arguments) {
+        return new ClassCastException(Strings.format(formatText, arguments));
+    }
+
     /**
      * Decorates a user expression node with a PainlessCast.
      */
@@ -252,13 +257,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (userBlockNode.getStatementNodes().isEmpty()) {
             throw userFunctionNode.createError(
                 new IllegalArgumentException(
-                    "invalid function definition: "
-                        + "found no statements for function "
-                        + "["
-                        + functionName
-                        + "] with ["
-                        + typeParameters.size()
-                        + "] parameters"
+                    Strings.format(
+                        "invalid function definition: found no statements for function [%s] with [%d] parameters",
+                        functionName,
+                        typeParameters.size()
+                    )
                 )
             );
         }
@@ -271,13 +274,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (methodEscape == false && isAutoReturnEnabled == false && returnType != void.class) {
             throw userFunctionNode.createError(
                 new IllegalArgumentException(
-                    "invalid function definition: "
-                        + "not all paths provide a return value for function "
-                        + "["
-                        + functionName
-                        + "] with ["
-                        + typeParameters.size()
-                        + "] parameters"
+                    Strings.format(
+                        "invalid function definition: not all paths provide a return value for function [%s] with [%d] parameters",
+                        functionName,
+                        typeParameters.size()
+                    )
                 )
             );
         }
@@ -751,14 +752,10 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (userValueNode == null) {
             if (semanticScope.getReturnType() != void.class) {
                 throw userReturnNode.createError(
-                    new ClassCastException(
-                        "cannot cast from "
-                            + "["
-                            + semanticScope.getReturnCanonicalTypeName()
-                            + "] to "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(void.class)
-                            + "]"
+                    castError(
+                        "cannot cast from [%s] to [%s]",
+                        semanticScope.getReturnCanonicalTypeName(),
+                        PainlessLookupUtility.typeToCanonicalTypeName(void.class)
                     )
                 );
             }
@@ -893,14 +890,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
 
         if (userCatchNode.getBaseException().isAssignableFrom(type) == false) {
             throw userCatchNode.createError(
-                new ClassCastException(
-                    "cannot cast from ["
-                        + PainlessLookupUtility.typeToCanonicalTypeName(type)
-                        + "] "
-                        + "to ["
-                        + PainlessLookupUtility.typeToCanonicalTypeName(baseException)
-                        + "]"
+                castError(
+                    "cannot cast from [%s] to [%s]",
+                    PainlessLookupUtility.typeToCanonicalTypeName(type),
+                    PainlessLookupUtility.typeToCanonicalTypeName(baseException)
                 )
+
             );
         }
 
@@ -1032,15 +1027,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
 
             if (compoundType == null || (isShift && shiftType == null)) {
                 throw userAssignmentNode.createError(
-                    new ClassCastException(
-                        "invalid compound assignment: "
-                            + "cannot apply ["
-                            + operation.symbol
-                            + "=] to types ["
-                            + leftValueType
-                            + "] and ["
-                            + rightValueType
-                            + "]"
+                    castError(
+                        "invalid compound assignment: cannot apply [%s=] to types [%s] and [%s]",
+                        operation.symbol,
+                        leftValueType,
+                        rightValueType
                     )
                 );
             }
@@ -1163,17 +1154,13 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
 
                 if (unaryType == null) {
                     throw userUnaryNode.createError(
-                        new ClassCastException(
-                            "cannot apply the "
-                                + operation.name
-                                + " operator "
-                                + "["
-                                + operation.symbol
-                                + "] to the type "
-                                + "["
-                                + PainlessLookupUtility.typeToCanonicalTypeName(childValueType)
-                                + "]"
+                        castError(
+                            "cannot apply the %s operator [%s] to the type [%s]",
+                            operation.name,
+                            operation.symbol,
+                            PainlessLookupUtility.typeToCanonicalTypeName(childValueType)
                         )
+
                     );
                 }
 
@@ -1268,20 +1255,14 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
 
             if (binaryType == null) {
                 throw userBinaryNode.createError(
-                    new ClassCastException(
-                        "cannot apply the "
-                            + operation.name
-                            + " operator "
-                            + "["
-                            + operation.symbol
-                            + "] to the types "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(leftValueType)
-                            + "] and "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
-                            + "]"
+                    castError(
+                        "cannot apply the %s operator [%s] to the types [%s] and [%s]",
+                        operation.name,
+                        operation.symbol,
+                        PainlessLookupUtility.typeToCanonicalTypeName(leftValueType),
+                        PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
                     )
+
                 );
             }
 
@@ -1405,19 +1386,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
 
         if (promotedType == null) {
             throw userCompNode.createError(
-                new ClassCastException(
-                    "cannot apply the "
-                        + operation.name
-                        + " operator "
-                        + "["
-                        + operation.symbol
-                        + "] to the types "
-                        + "["
-                        + PainlessLookupUtility.typeToCanonicalTypeName(leftValueType)
-                        + "] and "
-                        + "["
-                        + PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
-                        + "]"
+                castError(
+                    "cannot apply the %s operator [%s] to the types [%s] and [%s]",
+                    operation.name,
+                    operation.symbol,
+                    PainlessLookupUtility.typeToCanonicalTypeName(leftValueType),
+                    PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
                 )
             );
         }
@@ -1566,13 +1540,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
             if (promote == null) {
                 throw userConditionalNode.createError(
                     new ClassCastException(
-                        "cannot apply the conditional operator [?:] to the types "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(leftValueType)
-                            + "] and "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
-                            + "]"
+                        Strings.format(
+                            "cannot apply the conditional operator [?:] to the types [%s] and [%s]",
+                            PainlessLookupUtility.typeToCanonicalTypeName(leftValueType),
+                            PainlessLookupUtility.typeToCanonicalTypeName(rightValueType)
+                        )
                     )
                 );
             }
@@ -1822,12 +1794,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (semanticScope.getCondition(userNewObjNode, Write.class)) {
             throw userNewObjNode.createError(
                 new IllegalArgumentException(
-                    "invalid assignment cannot assign a value to new object with constructor "
-                        + "["
-                        + canonicalTypeName
-                        + "/"
-                        + userArgumentsSize
-                        + "]"
+                    Strings.format(
+                        "invalid assignment cannot assign a value to new object with constructor [%s/%d]",
+                        canonicalTypeName,
+                        userArgumentsSize
+                    )
                 )
             );
         }
@@ -1844,7 +1815,7 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (constructor == null) {
             throw userNewObjNode.createError(
                 new IllegalArgumentException(
-                    "constructor [" + typeToCanonicalTypeName(valueType) + ", <init>/" + userArgumentsSize + "] not found"
+                    Strings.format("constructor [%s, <init>/%d] not found", typeToCanonicalTypeName(valueType), userArgumentsSize)
                 )
             );
         }
@@ -1855,14 +1826,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (constructor.typeParameters().size() != userArgumentsSize) {
             throw userNewObjNode.createError(
                 new IllegalArgumentException(
-                    "When calling constructor on type ["
-                        + PainlessLookupUtility.typeToCanonicalTypeName(valueType)
-                        + "] "
-                        + "expected ["
-                        + constructor.typeParameters().size()
-                        + "] arguments, but found ["
-                        + userArgumentsSize
-                        + "]."
+                    Strings.format(
+                        "When calling constructor on type [%s] expected [%d] arguments, but found [%d].",
+                        PainlessLookupUtility.typeToCanonicalTypeName(valueType),
+                        constructor.typeParameters().size(),
+                        userArgumentsSize
+                    )
                 )
             );
         }
@@ -2295,13 +2264,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         } catch (PatternSyntaxException pse) {
             throw new Location(location.getSourceName(), location.getOffset() + 1 + pse.getIndex()).createError(
                 new IllegalArgumentException(
-                    "invalid regular expression: "
-                        + "could not compile regex constant ["
-                        + pattern
-                        + "] with flags ["
-                        + flags
-                        + "]: "
-                        + pse.getDescription(),
+                    Strings.format(
+                        "invalid regular expression: could not compile regex constant [%s] with flags [%s]: %s",
+                        pattern,
+                        flags,
+                        pse.getDescription()
+                    ),
                     pse
                 )
             );
@@ -2364,11 +2332,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
             }
             // check arity before we manipulate parameters
             if (interfaceMethod.typeParameters().size() != canonicalTypeNameParameters.size()) throw new IllegalArgumentException(
-                "Incorrect number of parameters for ["
-                    + interfaceMethod.javaMethod().getName()
-                    + "] in ["
-                    + targetType.getTargetCanonicalTypeName()
-                    + "]"
+                Strings.format(
+                    "Incorrect number of parameters for [%s] in [%s]",
+                    interfaceMethod.javaMethod().getName(),
+                    targetType.getTargetCanonicalTypeName()
+                )
             );
             // for method invocation, its allowed to ignore the return value
             if (interfaceMethod.returnType() == void.class) {
@@ -2725,13 +2693,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (prefixValueType != null && prefixStaticType != null) {
             throw userDotNode.createError(
                 new IllegalStateException(
-                    "cannot have both "
-                        + "value ["
-                        + prefixValueType.getValueCanonicalTypeName()
-                        + "] "
-                        + "and type ["
-                        + prefixStaticType.getStaticCanonicalTypeName()
-                        + "]"
+                    Strings.format(
+                        "cannot have both value [%s] and type [%s]",
+                        prefixValueType.getValueCanonicalTypeName(),
+                        prefixStaticType.getStaticCanonicalTypeName()
+                    )
                 )
             );
         }
@@ -3249,13 +3215,11 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
         if (prefixValueType != null && prefixStaticType != null) {
             throw userCallNode.createError(
                 new IllegalStateException(
-                    "cannot have both "
-                        + "value ["
-                        + prefixValueType.getValueCanonicalTypeName()
-                        + "] "
-                        + "and type ["
-                        + prefixStaticType.getStaticCanonicalTypeName()
-                        + "]"
+                    Strings.format(
+                        "cannot have both value [%s] and type [%s]",
+                        prefixValueType.getValueCanonicalTypeName(),
+                        prefixStaticType.getStaticCanonicalTypeName()
+                    )
                 )
             );
         }
@@ -3292,15 +3256,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
                     if (dynamic == false) {
                         throw userCallNode.createError(
                             new IllegalArgumentException(
-                                "member method "
-                                    + "["
-                                    + prefixValueType.getValueCanonicalTypeName()
-                                    + ", "
-                                    + methodName
-                                    + "/"
-                                    + userArgumentsSize
-                                    + "] "
-                                    + "not found"
+                                Strings.format(
+                                    "member method [%s, %s/%d] not found",
+                                    prefixValueType.getValueCanonicalTypeName(),
+                                    methodName,
+                                    userArgumentsSize
+                                )
                             )
                         );
                     }
@@ -3314,15 +3275,12 @@ public class DefaultSemanticAnalysisPhase extends UserTreeBaseVisitor<SemanticSc
             if (method == null) {
                 throw userCallNode.createError(
                     new IllegalArgumentException(
-                        "static method "
-                            + "["
-                            + prefixStaticType.getStaticCanonicalTypeName()
-                            + ", "
-                            + methodName
-                            + "/"
-                            + userArgumentsSize
-                            + "] "
-                            + "not found"
+                        Strings.format(
+                            "static method [%s, %s/%d] not found",
+                            prefixStaticType.getStaticCanonicalTypeName(),
+                            methodName,
+                            userArgumentsSize
+                        )
                     )
                 );
             }

+ 18 - 21
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultSemanticHeaderPhase.java

@@ -8,6 +8,7 @@
 
 package org.elasticsearch.painless.phase;
 
+import org.elasticsearch.core.Strings;
 import org.elasticsearch.painless.lookup.PainlessLookup;
 import org.elasticsearch.painless.node.SClass;
 import org.elasticsearch.painless.node.SFunction;
@@ -36,15 +37,13 @@ public class DefaultSemanticHeaderPhase extends UserTreeBaseVisitor<ScriptScope>
         if (parameterCount != parameterNames.size()) {
             throw userFunctionNode.createError(
                 new IllegalStateException(
-                    "invalid function definition: "
-                        + "parameter types size ["
-                        + canonicalTypeNameParameters.size()
-                        + "] is not equal to "
-                        + "parameter names size ["
-                        + parameterNames.size()
-                        + "] for function ["
-                        + functionName
-                        + "]"
+                    Strings.format(
+                        "invalid function definition: "
+                            + "parameter types size [%d] is not equal to parameter names size [%d] for function [%s]",
+                        canonicalTypeNameParameters.size(),
+                        parameterNames.size(),
+                        functionName
+                    )
                 )
             );
         }
@@ -65,12 +64,11 @@ public class DefaultSemanticHeaderPhase extends UserTreeBaseVisitor<ScriptScope>
         if (returnType == null) {
             throw userFunctionNode.createError(
                 new IllegalArgumentException(
-                    "invalid function definition: "
-                        + "return type ["
-                        + returnCanonicalTypeName
-                        + "] not found for function ["
-                        + functionKey
-                        + "]"
+                    Strings.format(
+                        "invalid function definition: return type [%s] not found for function [%s]",
+                        returnCanonicalTypeName,
+                        functionKey
+                    )
                 )
             );
         }
@@ -83,12 +81,11 @@ public class DefaultSemanticHeaderPhase extends UserTreeBaseVisitor<ScriptScope>
             if (paramType == null) {
                 throw userFunctionNode.createError(
                     new IllegalArgumentException(
-                        "invalid function definition: "
-                            + "parameter type ["
-                            + typeParameter
-                            + "] not found for function ["
-                            + functionKey
-                            + "]"
+                        Strings.format(
+                            "invalid function definition: parameter type [%s] not found for function [%s]",
+                            typeParameter,
+                            functionKey
+                        )
                     )
                 );
             }

+ 11 - 14
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/PainlessSemanticAnalysisPhase.java

@@ -8,6 +8,7 @@
 
 package org.elasticsearch.painless.phase;
 
+import org.elasticsearch.core.Strings;
 import org.elasticsearch.painless.AnalyzerCaster;
 import org.elasticsearch.painless.Location;
 import org.elasticsearch.painless.ScriptClassInfo;
@@ -77,13 +78,11 @@ public class PainlessSemanticAnalysisPhase extends DefaultSemanticAnalysisPhase
             if (userBlockNode.getStatementNodes().isEmpty()) {
                 throw userFunctionNode.createError(
                     new IllegalArgumentException(
-                        "invalid function definition: "
-                            + "found no statements for function "
-                            + "["
-                            + functionName
-                            + "] with ["
-                            + typeParameters.size()
-                            + "] parameters"
+                        Strings.format(
+                            "invalid function definition: found no statements for function [%s] with [%d] parameters",
+                            functionName,
+                            typeParameters.size()
+                        )
                     )
                 );
             }
@@ -161,13 +160,11 @@ public class PainlessSemanticAnalysisPhase extends DefaultSemanticAnalysisPhase
             if (semanticScope.getReturnType() != void.class) {
                 throw userReturnNode.createError(
                     new ClassCastException(
-                        "cannot cast from "
-                            + "["
-                            + semanticScope.getReturnCanonicalTypeName()
-                            + "] to "
-                            + "["
-                            + PainlessLookupUtility.typeToCanonicalTypeName(void.class)
-                            + "]"
+                        Strings.format(
+                            "cannot cast from [%s] to [%s]",
+                            semanticScope.getReturnCanonicalTypeName(),
+                            PainlessLookupUtility.typeToCanonicalTypeName(void.class)
+                        )
                     )
                 );
             }

+ 1 - 1
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/PainlessSemanticHeaderPhase.java

@@ -31,7 +31,7 @@ public class PainlessSemanticHeaderPhase extends DefaultSemanticHeaderPhase {
 
             if (functionTable.getFunction(functionKey) != null) {
                 throw userFunctionNode.createError(
-                    new IllegalArgumentException("invalid function definition: " + "found duplicate function [" + functionKey + "].")
+                    new IllegalArgumentException("invalid function definition: found duplicate function [" + functionKey + "].")
                 );
             }
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.