Skip to content

Commit 80186ee

Browse files
committed
It is safe to call String.format now
1 parent c382f2e commit 80186ee

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

java/client/src/com/thoughtworks/selenium/condition/Condition.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
// under the License.
1717
package com.thoughtworks.selenium.condition;
1818

19-
import java.lang.reflect.InvocationTargetException;
20-
import java.lang.reflect.Method;
21-
2219
/**
2320
* Simple predicate class, which also knows how to wait for the condition to be true. Used by
2421
* Selenium tests.
@@ -45,39 +42,15 @@ public Condition() {
4542

4643
/**
4744
* Creates an instance of Condition with the given {@code message} and {@code args}, which are in
48-
* the {@link String#format(String, Object...)} modeal.
45+
* the {@link String#format(String, Object...)} model.
4946
* @param message message
5047
* @param args args
5148
*/
5249
public Condition(String message, Object[] args) {
5350
if (null == message) {
5451
throw new NullPointerException("Condition names must not be null");
5552
}
56-
// this.message = String.format(message, args);
57-
this.message = simulateStringDotFormatMethod(message, args);
58-
}
59-
60-
private String simulateStringDotFormatMethod(String message, Object[] args) {
61-
int vers = Integer.parseInt(System.getProperty("java.class.version").substring(0, 2));
62-
if (vers >= 49) {
63-
try {
64-
Method format = String.class.getMethod("format", String.class, Object[].class);
65-
return (String) format.invoke(null, new Object[] {message, args});
66-
} catch (NoSuchMethodException | IllegalAccessException e) {
67-
} catch (InvocationTargetException e) {
68-
Throwable throwable = e.getCause();
69-
if (throwable instanceof RuntimeException) {
70-
throw (RuntimeException) throwable;
71-
}
72-
}
73-
throw new RuntimeException("String.format(..) can't be that hard to call");
74-
}
75-
String msg = "";
76-
msg = message;
77-
for (int i = 0; i < args.length; i++) {
78-
msg = msg + " " + args[i];
79-
}
80-
return msg;
53+
this.message = String.format(message, args);
8154
}
8255

8356
// drop these for var-args in another year.

0 commit comments

Comments
 (0)