Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing squid:S2275 - Printf-style format strings should not lead to unexpected behavior at runtime #63

Merged
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
2 changes: 1 addition & 1 deletion src/test/java/com/alibaba/ttl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static <T> void print(ConcurrentMap<String, TransmittableThreadLocal<T>>
for (Map.Entry<String, TransmittableThreadLocal<T>> entry : ttlInstances.entrySet()) {
String key = entry.getKey();
T value = entry.getValue().get();
System.out.printf("Key %s, value: %s\n", key, value);
System.out.printf("Key %s, value: %s%n", key, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void increaseSpanIdRefCounter() {
String traceId = dtTransferInfo.traceId;
int refCounter = traceId2LeafSpanIdInfo.get(traceId).refCounter.incrementAndGet();

System.out.printf("DEBUG: Increase reference counter(%s) for traceId %s in thread %s\n", refCounter, traceId, Thread.currentThread().getName());
System.out.printf("DEBUG: Increase reference counter(%s) for traceId %s in thread %s%n", refCounter, traceId, Thread.currentThread().getName());
}

static void decreaseSpanIdRefCounter() {
Expand All @@ -90,12 +90,12 @@ static void decreaseSpanIdRefCounter() {
LeafSpanIdInfo leafSpanIdInfo = traceId2LeafSpanIdInfo.get(traceId);

int refCounter = leafSpanIdInfo.refCounter.decrementAndGet();
System.out.printf("DEBUG: Decrease reference counter(%s) for traceId %s in thread %s\n", refCounter, traceId, Thread.currentThread().getName());
System.out.printf("DEBUG: Decrease reference counter(%s) for traceId %s in thread %s%n", refCounter, traceId, Thread.currentThread().getName());

if (refCounter == 0) {
traceId2LeafSpanIdInfo.remove(traceId);

System.out.printf("DEBUG: Clear traceId2LeafSpanIdInfo for traceId %s in thread %s\n", traceId, Thread.currentThread().getName());
System.out.printf("DEBUG: Clear traceId2LeafSpanIdInfo for traceId %s in thread %s%n", traceId, Thread.currentThread().getName());
} else if (refCounter < 0) {
throw new IllegalStateException("Leaf Span Id Info Reference counter has Bug!!");
}
Expand Down Expand Up @@ -188,6 +188,6 @@ static void invokeServerWithRpc(String server) {

// Do Rpc
// ...
System.out.printf("Do Rpc invocation to server %s with %s\n", server, rpcContext);
System.out.printf("Do Rpc invocation to server %s with %s%n", server, rpcContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String toString() {
// Output GC operation
@Override
protected void finalize() throws Throwable {
System.out.printf("DEBUG: gc DtTransferInfo traceId %s in thread %s: %s\n",
System.out.printf("DEBUG: gc DtTransferInfo traceId %s in thread %s: %s%n",
traceId, Thread.currentThread().getName(), this);
super.finalize();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ static void rpcInvokeIn() {
////////////////////////////////////////////////
// DistributedTracer Framework Code
////////////////////////////////////////////////
System.out.printf("Finished Rpc call %s with span %s.\n", traceId, leafSpanIdInfo);
System.out.printf("Finished Rpc call %s with span %s.%n", traceId, leafSpanIdInfo);

// release context in ThreadLocal, avoid to be hold by thread, GC friendly.
transferInfo.remove();
Expand Down Expand Up @@ -171,6 +171,6 @@ static void invokeServerWithRpc(String server) {

// Do Rpc
// ...
System.out.printf("Do Rpc invocation to server %s with %s\n", server, rpcContext);
System.out.printf("Do Rpc invocation to server %s with %s%n", server, rpcContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args) throws Exception {
threadLocal.set(Utils.getRandomString());

if (counter % 1000 == 0)
System.out.printf("%05dK\n", counter / 1000);
System.out.printf("%05dK%n", counter / 1000);
counter++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) throws Exception {
threadLocal.set(Utils.getRandomString());

if (counter % 1000 == 0)
System.out.printf("%05dK\n", counter / 1000);
System.out.printf("%05dK%n", counter / 1000);
counter++;
}
}
Expand Down