Instantly share code, notes, and snippets.

View Experiment.class
package sun.instrument;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.StubMethod;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.utility.JavaModule;
View GenericNestedTypeDemo.java
public class GenericNestedType {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface SampleTypeAnnotation { }
static class GenericNested<T> {
class Inner { }
}
View BugReportDeprecatedModifier.java
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.TraceClassVisitor;
import java.io.PrintWriter;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;
public class BugReportDeprecatedModifier {
View Main.java
package main;
import bar.Bar;
import qux.Qux;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Proxy;
import java.util.function.Consumer;
View StackWalkerExtraction.java
import org.openjdk.jmh.annotations.Benchmark;
public class StackWalkerExtraction {
private static Object call(int depth, Callable<?> result) throws Exception {
if (depth == 0) {
return result.call();
} else {
return call(depth - 1, result);
}
View Experiment.java
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.scaffold.InstrumentedType;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
import net.bytebuddy.pool.TypePool;
import org.objectweb.asm.*;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.SimpleRemapper;
View PackageConfustion.java
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.FixedValue;
import java.lang.reflect.Method;
import static net.bytebuddy.matcher.ElementMatchers.named;
public class PackageConfusion {
public static void main(String[] args) throws Exception {
View Benchmark
package test;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import foo.SampleBean;
import foo.SampleBeans;
View FileMonitor.java
import java.io.IOException;
import java.nio.file.*;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class FileMonitor implements Runnable {
View event.txt
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLOutputFactory xof = XMLOutputFactory.newFactory();
try (InputStream in = new FileInputStream("/home/rafael/foo.xml")) {
XMLEventReader xer = xif.createXMLEventReader(in);
XMLEventWriter xew = xof.createXMLEventWriter(System.out);
JAXBContext jc = JAXBContext.newInstance(Bar.class);