Skip to content

Commit 3f5497f

Browse files
committed
More explicit fix
1 parent 00b0c4f commit 3f5497f

3 files changed

Lines changed: 205 additions & 190 deletions

File tree

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/classicsdk/ApplicationInsightsAppenderClassFileTransformer.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ public class ApplicationInsightsAppenderClassFileTransformer implements ClassFil
2727
UnshadedSdkPackageName.get() + "/log4j/v2/ApplicationInsightsAppender";
2828
private static final String UNSHADED_CLASS_NAME_LOG_4_JV_1_2 =
2929
UnshadedSdkPackageName.get() + "/log4j/v1_2/ApplicationInsightsAppender";
30+
private static final String UNSHADED_DESCRIPTOR_LOGBACK =
31+
methodDescriptor("ch/qos/", "logback/classic/spi/ILoggingEvent");
32+
private static final String UNSHADED_DESCRIPTOR_LOG_4_JV_2 =
33+
methodDescriptor("org/apache/logging/log4j/core/LogEvent");
34+
private static final String UNSHADED_DESCRIPTOR_LOG_4_JV_1_2 =
35+
methodDescriptor("org/apache/log4j/spi/LoggingEvent");
36+
37+
private static String methodDescriptor(String parameterClassName) {
38+
return "(L" + parameterClassName + ";)V";
39+
}
40+
41+
private static String methodDescriptor(String firstPart, String secondPart) {
42+
return methodDescriptor(firstPart + secondPart);
43+
}
3044

3145
@Override
3246
@Nullable
@@ -72,10 +86,11 @@ public MethodVisitor visitMethod(
7286
@Nullable String signature,
7387
@Nullable String[] exceptions) {
7488
MethodVisitor mv = cw.visitMethod(access, name, descriptor, signature, exceptions);
75-
// match append(SomeLoggingEvent): the descriptor type-strings are not checked here
76-
// because Shadow relocates the "ch/qos/logback" literal, breaking the match at runtime;
77-
// class-name filtering in transform() already guarantees we are in the right class
78-
if (name.equals("append") && descriptor.startsWith("(L") && descriptor.endsWith(";)V")) {
89+
// Build the logback descriptor at runtime so Shadow cannot relocate the string literal.
90+
if (name.equals("append")
91+
&& (descriptor.equals(UNSHADED_DESCRIPTOR_LOGBACK)
92+
|| descriptor.equals(UNSHADED_DESCRIPTOR_LOG_4_JV_1_2)
93+
|| descriptor.equals(UNSHADED_DESCRIPTOR_LOG_4_JV_2))) {
7994
// no-op the append() method
8095
mv.visitCode();
8196
mv.visitInsn(RETURN);

gradlew.bat

Lines changed: 93 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)