It is safe to call `String.format` now
// under the License.
package com.thoughtworks.selenium.condition;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
/**
* Simple predicate class, which also knows how to wait for the condition to be true. Used by
* Selenium tests.
@@ -45,7 +42,7 @@ public Condition() {
/**
* Creates an instance of Condition with the given {@code message} and {@code args}, which are in
- * the {@link String#format(String, Object...)} modeal.
+ * the {@link String#format(String, Object...)} model.
* @param message message
* @param args args
*/
@@ -53,31 +50,7 @@ public Condition(String message, Object[] args) {
if (null == message) {
throw new NullPointerException("Condition names must not be null");
}
- // this.message = String.format(message, args);
- this.message = simulateStringDotFormatMethod(message, args);
- }
-
- private String simulateStringDotFormatMethod(String message, Object[] args) {
- int vers = Integer.parseInt(System.getProperty("java.class.version").substring(0, 2));
- if (vers >= 49) {
- try {
- Method format = String.class.getMethod("format", String.class, Object[].class);
- return (String) format.invoke(null, new Object[] {message, args});
- } catch (NoSuchMethodException | IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- Throwable throwable = e.getCause();
- if (throwable instanceof RuntimeException) {
- throw (RuntimeException) throwable;
- }
- }
- throw new RuntimeException("String.format(..) can't be that hard to call");
- }
- String msg = "";
- msg = message;
- for (int i = 0; i < args.length; i++) {
- msg = msg + " " + args[i];
- }
- return msg;
+ this.message = String.format(message, args);
}
// drop these for var-args in another year.
