Skip to content

Commit f03bda4

Browse files
committed
Use Locale.ROOT with String.format which does or could render numbers
1 parent 9c6342c commit f03bda4

30 files changed

Lines changed: 72 additions & 41 deletions

spock-core/src/main/java/org/spockframework/compiler/ErrorReporter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.codehaus.groovy.control.SourceUnit;
2121
import org.codehaus.groovy.control.messages.*;
2222

23+
import java.util.Locale;
24+
2325
/**
2426
* Reporting facility for problems found during compilation.
2527
* In general, error(ASTNode) is the preferred method to use.
@@ -40,12 +42,12 @@ public ErrorReporter(SourceUnit sourceUnit) {
4042

4143
public void error(String msg, Object... args) {
4244
sourceUnit.getErrorCollector().addErrorAndContinue(
43-
new SimpleMessage(String.format(msg, args), sourceUnit));
45+
new SimpleMessage(String.format(Locale.ROOT, msg, args), sourceUnit));
4446
}
4547

4648
public void error(String msg, Throwable cause, Object... args) {
4749
sourceUnit.getErrorCollector().addErrorAndContinue(
48-
new SimpleMessage(String.format(msg, args) + "\n\n" + TextUtil.printStackTrace(cause), sourceUnit));
50+
new SimpleMessage(String.format(Locale.ROOT, msg, args) + "\n\n" + TextUtil.printStackTrace(cause), sourceUnit));
4951
}
5052

5153
public void error(ASTNode node, String msg, Object... args) {

spock-core/src/main/java/org/spockframework/compiler/InvalidSpecCompileException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.codehaus.groovy.ast.ASTNode;
2020
import org.codehaus.groovy.syntax.SyntaxException;
2121

22+
import java.util.Locale;
23+
2224
/**
2325
* Indicates that a spec was found to contain a (syntactic or semantic)
2426
* error during compilation. As such, this is the compile-time equivalent
@@ -33,7 +35,7 @@
3335
*/
3436
public class InvalidSpecCompileException extends SyntaxException {
3537
public InvalidSpecCompileException(int line, int column, String msg, Object... args) {
36-
super(String.format(msg, args), line, column);
38+
super(String.format(Locale.ROOT, msg, args), line, column);
3739
}
3840

3941
public InvalidSpecCompileException(ASTNode node, String msg, Object... args) {

spock-core/src/main/java/org/spockframework/compiler/SpecRewriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ private void transplantMethod(Method method) {
340340
}
341341

342342
private String createInternalName(FeatureMethod feature) {
343-
return String.format("$spock_feature_%d_%d", specDepth, feature.getOrdinal());
343+
return String.format(Locale.ROOT, "$spock_feature_%d_%d", specDepth, feature.getOrdinal());
344344
}
345345

346346
private MethodNode copyMethod(MethodNode method, String newName) {

spock-core/src/main/java/org/spockframework/compiler/WhereBlockRewriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ private void rewriteTableLikeParameterization(ListIterator<Statement> stats, Fun
576576
// and the row to be added does not have the same size as previous rows
577577
// => compile error
578578
if (rows.size() > 0 && rows.getLast().size() != row.size())
579-
throw new InvalidSpecCompileException(row.get(0), String.format("Row in data table has wrong number of elements (%s instead of %s)", row.size(), rows.getLast().size()));
579+
throw new InvalidSpecCompileException(row.get(0), String.format(Locale.ROOT, "Row in data table has wrong number of elements (%d instead of %d)", row.size(), rows.getLast().size()));
580580

581581
// add the new row
582582
rows.add(row);

spock-core/src/main/java/org/spockframework/mock/runtime/ByteBuddyMockFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import java.lang.reflect.Method;
4747
import java.util.Collection;
48+
import java.util.Locale;
4849
import java.util.concurrent.Callable;
4950
import java.util.concurrent.ThreadLocalRandom;
5051

@@ -125,7 +126,7 @@ Object createMock(IMockMaker.IMockCreationSettings settings) {
125126
targetClass = CODEGEN_TARGET_CLASS;
126127
}
127128
int randomNumber = Math.abs(ThreadLocalRandom.current().nextInt());
128-
String name = String.format("%s$%s$%d", typeName, "SpockMock", randomNumber);
129+
String name = String.format(Locale.ROOT, "%s$%s$%d", typeName, "SpockMock", randomNumber);
129130
ClassLoadingStrategy<ClassLoader> strategy = determineBestClassLoadingStrategy(targetClass, settings);
130131
//noinspection resource
131132
return new ByteBuddy()

spock-core/src/main/java/org/spockframework/mock/runtime/MockInteraction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,6 @@ public String getText() {
179179
}
180180

181181
public String toString() {
182-
return String.format("%s (%d %s)", text, acceptedInvocations.size(), acceptedInvocations.size() == 1 ? "invocation" : "invocations");
182+
return String.format(Locale.ROOT, "%s (%d %s)", text, acceptedInvocations.size(), acceptedInvocations.size() == 1 ? "invocation" : "invocations");
183183
}
184184
}

spock-core/src/main/java/org/spockframework/runtime/DataVariablesIterationNameProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String getName(IterationInfo iteration) {
5959
});
6060
}
6161
if (includeIterationIndex) {
62-
nameJoiner.add(format("#%d", iteration.getIterationIndex()));
62+
nameJoiner.add(format(Locale.ROOT, "#%d", iteration.getIterationIndex()));
6363
}
6464
return includeFeatureNameForIterations ? format("%s [%s]", feature.getName(), nameJoiner) : nameJoiner.toString();
6565
}

spock-core/src/main/java/org/spockframework/runtime/FailedSetEqualityComparisonRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public String render(ExpressionInfo expr) {
3131
int differences = missingSize + extraSize;
3232

3333
if (editDistance < 11)
34-
return String.format("false%n%d difference%s (%d%% similarity, %d missing, %d extra)%nmissing: %s%nextra: %s",
34+
return String.format(Locale.ROOT, "false%n%d difference%s (%d%% similarity, %d missing, %d extra)%nmissing: %s%nextra: %s",
3535
differences,
3636
differences == 1 ? "" : "s",
3737
similarityInPercent,
3838
missingSize, extraSize,
3939
missing, extra);
4040

41-
return String.format("false%n%d differences (%d%% similarity, %d missing, %d extra)%nmissing/extra: too many to render",
41+
return String.format(Locale.ROOT, "false%n%d differences (%d%% similarity, %d missing, %d extra)%nmissing/extra: too many to render",
4242
differences,
4343
similarityInPercent,
4444
missingSize, extraSize);

spock-core/src/main/java/org/spockframework/runtime/FailedStringComparisonRenderer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import groovy.lang.GString;
77

8+
import java.util.Locale;
9+
810
public class FailedStringComparisonRenderer implements ExpressionComparisonRenderer {
911
public static final long MAX_EDIT_DISTANCE_MEMORY = 50 * 1024;
1012
@Override
@@ -56,7 +58,7 @@ private String tryReduceStringSizes(String str1, String str2) {
5658

5759
private String createAndRenderEditDistance(String str1, String str2) {
5860
EditDistance dist = new EditDistance(str1, str2);
59-
return String.format("false\n%d difference%s (%d%% similarity)\n%s",
61+
return String.format(Locale.ROOT, "false\n%d difference%s (%d%% similarity)\n%s",
6062
dist.getDistance(), dist.getDistance() == 1 ? "" : "s", dist.getSimilarityInPercent(),
6163
new EditPathRenderer().render(str1, str2, dist.calculatePath()));
6264
}
@@ -65,7 +67,7 @@ private String createAndRenderEditDistance(String str1, String str2, int commonS
6567
String sub1 = str1.substring(commonStart, end1);
6668
String sub2 = str2.substring(commonStart, end2);
6769
EditDistance dist = new EditDistance(sub1, sub2);
68-
return String.format("false\n%d difference%s (%d%% similarity) (comparing subset start: %d, end1: %d, end2: %d)\n%s",
70+
return String.format(Locale.ROOT, "false\n%d difference%s (%d%% similarity) (comparing subset start: %d, end1: %d, end2: %d)\n%s",
6971
dist.getDistance(), dist.getDistance() == 1 ? "" : "s", dist.getSimilarityInPercent(),
7072
commonStart, end1, end2,
7173
new EditPathRenderer().render(sub1, sub2, dist.calculatePath()));

spock-core/src/main/java/org/spockframework/runtime/InvalidSpecException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.spockframework.runtime;
1818

19+
import java.util.Locale;
20+
1921
/**
2022
* Indicates that a Spec has done something it is not supposed to do. It is up
2123
* to the Spec author to correct the problem.
@@ -35,7 +37,7 @@ public InvalidSpecException(String msg, Throwable throwable) {
3537
}
3638

3739
public InvalidSpecException withArgs(Object... args) {
38-
msg = String.format(msg, args);
40+
msg = String.format(Locale.ROOT, msg, args);
3941
return this;
4042
}
4143

0 commit comments

Comments
 (0)