Repository navigation
public static void premain(String args, Instrumentation instrumentation) {
PluginFinder pluginFinder = null;
try {
PluginBootstrap pluginBootstrap = new PluginBootstrap();
pluginFinder = new PluginFinder(pluginBootstrap.loadPlugins());
} catch (Exception e) {
return;
}
ByteBuddy byteBuddy = new ByteBuddy().with(TypeValidation.of(true));
AgentBuilder.Default builder = new AgentBuilder.Default(byteBuddy);
builder.type(pluginFinder.buildMatch())
.transform(new Transformer(pluginFinder))
.with(new BytebuddyListener())
.installOn(instrumentation);
}
public ElementMatcher getMethodsMatcher() {
return ElementMatchers.named("getAlternative")
.and(ElementMatchers.takesArguments(4))
.and(ElementMatchers.isStatic());
}When I attempted to intercept the first getAlternative method, package com.ctrip.di.data.abtest.client;
import com.ctrip.di.data.abtest.client.config.WebContext;
import com.ctrip.di.data.abtest.client.exception.ABTestException;
import com.ctrip.di.data.abtest.client.exception.ErrorCode;
import com.ctrip.di.data.abtest.client.service.ABTestUBTService;
import com.ctrip.di.data.abtest.client.util.CLogUtil;
import com.ctrip.di.data.abtest.client.util.MetricsUtil;
import com.ctrip.di.data.abtest.client.util.Util;
import com.ctrip.di.data.abtestmetadataservice.Metadata;
import com.ctrip.di.data.abtestservice.Alternative;
import com.ctrip.framework.clogging.agent.log.ILog;
import com.ctrip.framework.clogging.agent.log.LogManager;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
public final class ABTestClient {
private static final ILog LOGGER = LogManager.getLogger(ABTestClient.class);
private static final String GET_ALTERNATIVE = "getAlternative";
private static final String GET_ALTERNATIVE_BY_KEY = "getAlternativeByKey";
private static final String GET_ALTERNATIVE_WEB = "getAlternativeOfWeb";
private static final String LOAD = "load";
private static final String LOAD_BY_KEY = "loadByKey";
private static final String LOAD_BY_BU = "loadByBu";
private static final String LOAD_ALL = "loadAll";
public ABTestClient() {
}
public static Alternative getAlternative(String expCode, String divisionID, Boolean sendUbt, Map<String, String> ubt) {
return getAlternative(expCode, divisionID, sendUbt, ubt, (String)null, (String)null, (String)null, (String)null, (Boolean)null);
}
public static Alternative getAlternative(String expCode, String divisionID, Boolean sendUbt, Map<String, String> ubt, String kafkaTopic) {
return getAlternative(expCode, divisionID, sendUbt, ubt, (String)null, (String)null, (String)null, kafkaTopic, (Boolean)null);
}
public static Alternative getAlternative(String expCode, String divisionID, Boolean sendUbt, Map<String, String> ubt, String kafkaTopic, Boolean recordLog) {
return getAlternative(expCode, divisionID, sendUbt, ubt, (String)null, (String)null, (String)null, kafkaTopic, recordLog);
}
public static Alternative getAlternative(String expCode, String divisionID, Boolean sendUbt, Map<String, String> ubt, Boolean recordLog) {
return getAlternative(expCode, divisionID, sendUbt, ubt, (String)null, (String)null, (String)null, (String)null, recordLog);
}
public static Alternative getAlternative(String expCode, String divisionID, Boolean sendUbt, Map<String, String> ubt, String systemCode, String appId, String appVer, String kafkaTopic, Boolean recordLog) {
CLogUtil log = new CLogUtil(expCode, divisionID, recordLog);
Alternative alternative = null;
long start = System.currentTimeMillis();
try {
if (StringUtils.isBlank(expCode)) {
throw new ABTestException(ErrorCode.BLANK_EXPCODE, expCode);
}
if (StringUtils.isBlank(divisionID)) {
throw new ABTestException(ErrorCode.BLANK_DIVISIONID, divisionID);
}
if (!expCode.matches("[_\\w]+")) {
throw new ABTestException(ErrorCode.INVALID_EXPCODE, expCode);
}
MetricsUtil.requestCount(expCode);
alternative = ABClientCache.getInstance().getAlternative(expCode, divisionID, systemCode, appId, appVer);
log.info(LOGGER, "getAlternative", "sendUbt: " + sendUbt + "kafkaTopic:" + kafkaTopic + ",alternative:" + alternative);
if (sendUbt == null || sendUbt) {
ABTestUBTService.sendUBT(alternative, ubt, kafkaTopic, appId);
}
MetricsUtil.requestLatency(start, alternative);
} catch (Exception e) {
if (alternative == null) {
alternative = new Alternative(expCode, (String)null, divisionID, "A", -1, (String)null, (String)null, (Map)null);
}
log.warn(LOGGER, "getAlternative", e);
MetricsUtil.requestExceptionCount(expCode, e);
}
return alternative;
}
public static Alternative getAlternativeByKey(String keyName, String keyParam, String divisionID, Boolean sendUbt, Map<String, String> ubt) {
return getAlternativeByKey(keyName, keyParam, divisionID, sendUbt, ubt, (String)null, (String)null, (String)null);
}
public static Alternative getAlternativeByKey(String keyName, String keyParam, String divisionID, Boolean sendUbt, Map<String, String> ubt, String systemCode, String appId, String appVer) {
String expCode = Util.join("_", new String[]{keyName, keyParam});
CLogUtil log = new CLogUtil(expCode, divisionID, (Boolean)null);
Alternative alternative = null;
long start = System.currentTimeMillis();
try {
if (StringUtils.isBlank(expCode)) {
throw new ABTestException(ErrorCode.BLANK_EXPCODE, expCode);
}
if (StringUtils.isBlank(divisionID)) {
throw new ABTestException(ErrorCode.BLANK_DIVISIONID, divisionID);
}
log.info(LOGGER, "getAlternativeByKey", "sendUbt: " + sendUbt + ", ubt: " + ubt + ", systemCode: " + systemCode + ", appId: " + appId + ", appVer: " + appVer);
MetricsUtil.requestCount(expCode);
alternative = ABClientCache.getInstance().getAlternative(expCode, divisionID, systemCode, appId, appVer);
log.info(LOGGER, "getAlternativeByKey", alternative);
if (sendUbt == null || sendUbt) {
ABTestUBTService.sendUBT(alternative, ubt, (String)null, appId);
}
MetricsUtil.requestLatency(start, alternative);
} catch (Exception e) {
if (alternative == null) {
alternative = new Alternative(expCode, (String)null, divisionID, "A", -1, (String)null, (String)null, (Map)null);
}
log.warn(LOGGER, "getAlternativeByKey", e);
MetricsUtil.requestExceptionCount(expCode, e);
}
return alternative;
}
public static Alternative getAlternativeOfWeb(String expCode, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
return getAlternativeOfWeb(expCode, httpRequest, httpResponse, (String)null, (String)null, (String)null);
}the following error occurred: |
Replies: 6 comments 5 replies
|
Seems like your class loader cannot read class files, or there is an optional type that is missing, so Byte Buddy cannot resolve it. Either you have to add your own class file resolver, or you have to adjust your instrumentation to not request for that information. Possibly, you can also ignore the error, if it affects an unrelated type instrumentation. |
|
Thanks for your reply. You mean that TypeValidation.of(false) can reduce type checking, and it is not inherently unsafe. However, setting it to true can prevent some serious errors. Additionally, I would like to know under which circumstances severe crashes may occur. |
|
Mainly once you add custom instrumentations. Byte Buddy's built in instrumentations do most checking less invasively themselves. |
|
Would you mean that when a custom instrument is not utilized, this value may be set to false and is safe in the majority of scenarios?
…---- Replied Message ----
| From | Rafael ***@***.***> |
| Date | 12/07/2025 18:03 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [raphw/byte-buddy] Resolution$NoSuchTypeException (Discussion #1876) |
Mainly once you add custom instrumentations. Byte Buddy's built in instrumentations do most checking less invasively themselves.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
Thank you for your assistance. I will give it a try
…---- Replied Message ----
| From | Rafael ***@***.***> |
| Date | 12/07/2025 18:12 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [raphw/byte-buddy] Resolution$NoSuchTypeException (Discussion #1876) |
There's always a chance for bugs, but the same is true for the validation. So yes.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
This API has been deprecated in Tomcat 10. We restored normal functionality by using jakarta.servlet. |
This API has been deprecated in Tomcat 10. We restored normal functionality by using jakarta.servlet.