Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.messages.*;

import java.util.Locale;

/**
* Reporting facility for problems found during compilation.
* In general, error(ASTNode) is the preferred method to use.
Expand All @@ -40,12 +42,12 @@ public ErrorReporter(SourceUnit sourceUnit) {

public void error(String msg, Object... args) {
sourceUnit.getErrorCollector().addErrorAndContinue(
new SimpleMessage(String.format(msg, args), sourceUnit));
new SimpleMessage(String.format(Locale.ROOT, msg, args), sourceUnit));
}

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

public void error(ASTNode node, String msg, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.syntax.SyntaxException;

import java.util.Locale;

/**
* Indicates that a spec was found to contain a (syntactic or semantic)
* error during compilation. As such, this is the compile-time equivalent
Expand All @@ -33,7 +35,7 @@
*/
public class InvalidSpecCompileException extends SyntaxException {
public InvalidSpecCompileException(int line, int column, String msg, Object... args) {
super(String.format(msg, args), line, column);
super(String.format(Locale.ROOT, msg, args), line, column);
}

public InvalidSpecCompileException(ASTNode node, String msg, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void transplantMethod(Method method) {
}

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

private MethodNode copyMethod(MethodNode method, String newName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ private void rewriteTableLikeParameterization(ListIterator<Statement> stats, Fun
// and the row to be added does not have the same size as previous rows
// => compile error
if (rows.size() > 0 && rows.getLast().size() != row.size())
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()));
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()));

// add the new row
rows.add(row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -125,7 +126,7 @@ Object createMock(IMockMaker.IMockCreationSettings settings) {
targetClass = CODEGEN_TARGET_CLASS;
}
int randomNumber = Math.abs(ThreadLocalRandom.current().nextInt());
String name = String.format("%s$%s$%d", typeName, "SpockMock", randomNumber);
String name = String.format(Locale.ROOT, "%s$%s$%d", typeName, "SpockMock", randomNumber);
ClassLoadingStrategy<ClassLoader> strategy = determineBestClassLoadingStrategy(targetClass, settings);
//noinspection resource
return new ByteBuddy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ public String getText() {
}

public String toString() {
return String.format("%s (%d %s)", text, acceptedInvocations.size(), acceptedInvocations.size() == 1 ? "invocation" : "invocations");
return String.format(Locale.ROOT, "%s (%d %s)", text, acceptedInvocations.size(), acceptedInvocations.size() == 1 ? "invocation" : "invocations");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getName(IterationInfo iteration) {
});
}
if (includeIterationIndex) {
nameJoiner.add(format("#%d", iteration.getIterationIndex()));
nameJoiner.add(format(Locale.ROOT, "#%d", iteration.getIterationIndex()));
}
return includeFeatureNameForIterations ? format("%s [%s]", feature.getName(), nameJoiner) : nameJoiner.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public String render(ExpressionInfo expr) {
int differences = missingSize + extraSize;

if (editDistance < 11)
return String.format("false%n%d difference%s (%d%% similarity, %d missing, %d extra)%nmissing: %s%nextra: %s",
return String.format(Locale.ROOT, "false%n%d difference%s (%d%% similarity, %d missing, %d extra)%nmissing: %s%nextra: %s",
differences,
differences == 1 ? "" : "s",
similarityInPercent,
missingSize, extraSize,
missing, extra);

return String.format("false%n%d differences (%d%% similarity, %d missing, %d extra)%nmissing/extra: too many to render",
return String.format(Locale.ROOT, "false%n%d differences (%d%% similarity, %d missing, %d extra)%nmissing/extra: too many to render",
differences,
similarityInPercent,
missingSize, extraSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import groovy.lang.GString;

import java.util.Locale;

public class FailedStringComparisonRenderer implements ExpressionComparisonRenderer {
public static final long MAX_EDIT_DISTANCE_MEMORY = 50 * 1024;
@Override
Expand Down Expand Up @@ -56,7 +58,7 @@ private String tryReduceStringSizes(String str1, String str2) {

private String createAndRenderEditDistance(String str1, String str2) {
EditDistance dist = new EditDistance(str1, str2);
return String.format("false\n%d difference%s (%d%% similarity)\n%s",
return String.format(Locale.ROOT, "false\n%d difference%s (%d%% similarity)\n%s",
dist.getDistance(), dist.getDistance() == 1 ? "" : "s", dist.getSimilarityInPercent(),
new EditPathRenderer().render(str1, str2, dist.calculatePath()));
}
Expand All @@ -65,7 +67,7 @@ private String createAndRenderEditDistance(String str1, String str2, int commonS
String sub1 = str1.substring(commonStart, end1);
String sub2 = str2.substring(commonStart, end2);
EditDistance dist = new EditDistance(sub1, sub2);
return String.format("false\n%d difference%s (%d%% similarity) (comparing subset start: %d, end1: %d, end2: %d)\n%s",
return String.format(Locale.ROOT, "false\n%d difference%s (%d%% similarity) (comparing subset start: %d, end1: %d, end2: %d)\n%s",
dist.getDistance(), dist.getDistance() == 1 ? "" : "s", dist.getSimilarityInPercent(),
commonStart, end1, end2,
new EditPathRenderer().render(sub1, sub2, dist.calculatePath()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.spockframework.runtime;

import java.util.Locale;

/**
* Indicates that a Spec has done something it is not supposed to do. It is up
* to the Spec author to correct the problem.
Expand All @@ -35,7 +37,7 @@ public InvalidSpecException(String msg, Throwable throwable) {
}

public InvalidSpecException withArgs(Object... args) {
msg = String.format(msg, args);
msg = String.format(Locale.ROOT, msg, args);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import org.spockframework.runtime.model.*;

import java.util.Locale;

import static java.lang.String.format;

public class SafeIterationNameProvider implements NameProvider<IterationInfo> {
Expand All @@ -40,7 +42,7 @@ public String getName(IterationInfo iteration) {

private String getFallbackName(IterationInfo iteration) {
return iteration.getFeature().isReportIterations()
? format("%s [#%d]", iteration.getFeature().getName(), iteration.getIterationIndex())
? format(Locale.ROOT, "%s [#%d]", iteration.getFeature().getName(), iteration.getIterationIndex())
: iteration.getFeature().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.spockframework.runtime;

import java.util.Locale;

/**
* Indicates that a problem occurred during Spec execution.
*
Expand All @@ -34,7 +36,7 @@ public SpockExecutionException(String msg, Throwable throwable) {
}

public SpockExecutionException withArgs(Object... args) {
msg = String.format(msg, args);
msg = String.format(Locale.ROOT, msg, args);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static <T> void verifyEach(
}

private static <T> SpockAssertionError getAssertionFailedError(Function<? super T, ?> namer, InternalItemFailure<T> failure) {
SpockAssertionError error = new SpockAssertionError(String.format("Assertions failed for item[%d] %s:\n%s", failure.index, namer.apply(failure.item), failure.throwable.toString()));
SpockAssertionError error = new SpockAssertionError(String.format(Locale.ROOT, "Assertions failed for item[%d] %s:\n%s", failure.index, namer.apply(failure.item), failure.throwable.toString()));
error.setStackTrace(failure.throwable.getStackTrace());
return error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.spockframework.runtime.SpockException;

import java.util.Locale;

public class ExtensionException extends SpockException {
private String message;

Expand All @@ -31,7 +33,7 @@ public ExtensionException(String message, Throwable cause) {
}

public ExtensionException withArgs(Object... args) {
message = String.format(message, args);
message = String.format(Locale.ROOT, message, args);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void intercept(final IMethodInvocation invocation) throws Throwable {
// act accordingly. We gloss over the fact that some other thread might also have tried to
// interrupt this thread. This shouldn't be a problem in practice, in particular because
// throwing an InterruptedException wouldn't abort the whole test run anyway.
String msg = String.format("Method timed out after %1.2f seconds", timeoutSeconds);
String msg = String.format(Locale.ROOT, "Method timed out after %1.2f seconds", timeoutSeconds);
SpockTimeoutError error = new SpockTimeoutError(timeoutSeconds, msg);
error.setStackTrace(stackTrace);
throw error;
Expand All @@ -134,6 +135,7 @@ public void intercept(final IMethodInvocation invocation) throws Throwable {

private void logUnsuccessfulInterrupt(String methodName, long now, long timeoutAt, long waitMillis, int unsuccessfulAttempts) {
System.err.printf(
Locale.ROOT,
"[spock.lang.Timeout] Method '%s' has not stopped after timing out %1.2f seconds ago - interrupting. Next try in %1.2f seconds.\n%n",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Minor: Redundant newline characters.

The format string has both \n (literal newline) and %n (platform-specific line separator) at the end, resulting in double newlines in the output.

🔧 Suggested fix
-      "[spock.lang.Timeout] Method '%s' has not stopped after timing out %1.2f seconds ago - interrupting. Next try in %1.2f seconds.\n%n",
+      "[spock.lang.Timeout] Method '%s' has not stopped after timing out %1.2f seconds ago - interrupting. Next try in %1.2f seconds.%n",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"[spock.lang.Timeout] Method '%s' has not stopped after timing out %1.2f seconds ago - interrupting. Next try in %1.2f seconds.\n%n",
"[spock.lang.Timeout] Method '%s' has not stopped after timing out %1.2f seconds ago - interrupting. Next try in %1.2f seconds.%n",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@spock-core/src/main/java/org/spockframework/runtime/extension/builtin/TimeoutInterceptor.java`
at line 139, In TimeoutInterceptor.java (class TimeoutInterceptor), the format
string used when logging the timeout message includes both a literal "\n" and
"%n", causing double newlines; update the format string in the logging/format
call (the string starting with "[spock.lang.Timeout] Method '%s'...") to use a
single platform-specific line separator (prefer %n) and remove the redundant
"\n" so the message ends with only "%n".

methodName,
TimeUtil.toSeconds(Duration.ofNanos(now - timeoutAt)),
Expand All @@ -152,6 +154,7 @@ private void logUnsuccessfulInterrupt(String methodName, long now, long timeoutA

private void logMethodTimeout(String methodName, double timeoutSeconds) {
System.err.printf(
Locale.ROOT,
"[spock.lang.Timeout] Method '%s' timed out after %1.2f seconds.%n",
methodName,
timeoutSeconds
Expand Down Expand Up @@ -206,7 +209,7 @@ private static Pair<Integer, Integer> findThreadSection(List<String> lines, Stri
String lineFormat = "\"%s\" #%d";
int threadSectionStart = -1;
for (int i = 0; i < lines.size(); ++i) {
if (lines.get(i).startsWith(String.format(lineFormat, threadName, threadId))) {
if (lines.get(i).startsWith(String.format(Locale.ROOT, lineFormat, threadName, threadId))) {
threadSectionStart = i;
} else if (threadSectionStart > 0 && lines.get(i).isEmpty()) {
return Pair.of(threadSectionStart, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.spockframework.runtime.model;

import java.io.Serializable;
import java.util.Locale;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.syntax.Token;
Expand Down Expand Up @@ -79,7 +80,7 @@ public int hashCode() {
}

public String toString() {
return String.format("(%d,%d)", line, column);
return String.format(Locale.ROOT, "(%d,%d)", line, column);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions spock-core/src/main/java/org/spockframework/util/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jetbrains.annotations.Contract;

import java.util.Locale;
import java.util.function.Supplier;

/**
Expand All @@ -33,7 +34,7 @@ public static <T> T notNull(T obj) {

@Contract("null, _, _ -> fail")
public static <T> T notNull(T obj, String msg, Object... values) {
if (obj == null) throw new InternalSpockError(String.format(msg, values));
if (obj == null) throw new InternalSpockError(String.format(Locale.ROOT, msg, values));
return obj;
}

Expand All @@ -44,7 +45,7 @@ public static void that(boolean condition) {

@Contract("false, _, _ -> fail")
public static void that(boolean condition, String msg, Object... values) {
if (!condition) throw new InternalSpockError(String.format(msg, values));
if (!condition) throw new InternalSpockError(String.format(Locale.ROOT, msg, values));
}

public static void that(boolean condition, Supplier<String> msgSupplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.spockframework.util;

import java.util.Locale;

/**
*
* @author Peter Niederwieser
Expand Down Expand Up @@ -46,6 +48,6 @@ public InternalSpockError withArgs(Object... msgArgs) {

@Override
public String getMessage() {
return String.format(super.getMessage(), msgArgs);
return String.format(Locale.ROOT, super.getMessage(), msgArgs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private static void checkSameSize(File source, File target) throws IOException {

if (fromSize != toSize)
throw new IOException(String.format(
Locale.ROOT,
"Error copying file %s to %s; source file size is %d, but target file size is %d",
source, target, fromSize, toSize));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.spockframework.util;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -96,7 +97,7 @@ public int hashCode() {
}

public String toString() {
return String.format(versionTemplate, major, minor, micro, (qualifier == null ? "" : "-" + getQualifier()) + (isSnapshot ? "-SNAPSHOT" : ""));
return String.format(Locale.ROOT, versionTemplate, major, minor, micro, (qualifier == null ? "" : "-" + getQualifier()) + (isSnapshot ? "-SNAPSHOT" : ""));
}

public String toOriginalString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@

package spock.config;

import java.util.Locale;

/**
* Thrown to indicate that there is a problem with Spock's configuration (file).
*
* @author Peter Niederwieser
*/
public class ConfigurationException extends RuntimeException {
public ConfigurationException(String msg, Object... args) {
super(String.format(msg, args));
super(String.format(Locale.ROOT, msg, args));
}
public ConfigurationException(String msg, Throwable t, Object... args) {
super(String.format(msg, args), t);
super(String.format(Locale.ROOT, msg, args), t);
}
}
6 changes: 3 additions & 3 deletions spock-core/src/main/java/spock/lang/Snapshotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public Store(IterationInfo iterationInfo, Path rootPath, boolean updateSnapshots

private static String calculateSafeUniqueName(String extension, IterationInfo iterationInfo, String snapshotId) {
Checks.checkArgument(snapshotId.length() <= 100,
() -> String.format("'snapshotId' is too long, only 100 characters are allowed, but was %d: %s", snapshotId.length(), snapshotId));
() -> String.format(Locale.ROOT, "'snapshotId' is too long, only 100 characters are allowed, but was %d: %s", snapshotId.length(), snapshotId));

FeatureInfo feature = iterationInfo.getFeature();
String safeName = sanitize(feature.getName());
Expand All @@ -296,9 +296,9 @@ private static String calculateSafeUniqueName(String extension, IterationInfo it
int uniqueSuffixLength = 1 + featureId.length() + 1 + extension.length() + iterationIndex.length() + snapshotIdSuffix.length();
if (safeName.length() + uniqueSuffixLength > 250) {
safeName = safeName.substring(0, 250 - uniqueSuffixLength);
return String.format(Locale.ROOT, "%s%s-%s%s.%s", safeName, snapshotIdSuffix, featureId, iterationIndex, extension);
return String.format("%s%s-%s%s.%s", safeName, snapshotIdSuffix, featureId, iterationIndex, extension);
}
return String.format(Locale.ROOT, "%s%s%s.%s", safeName, snapshotIdSuffix, iterationIndex, extension);
return String.format("%s%s%s.%s", safeName, snapshotIdSuffix, iterationIndex, extension);
}

private static String sanitize(String snapshotId) {
Expand Down
Loading
Loading