Skip to content

Instantly share code, notes, and snippets.

View raphw's full-sized avatar

Rafael Winterhalter raphw

View GitHub Profile
@raphw
raphw / Foo.java
Created January 12, 2016 15:26
A receiver type is not resolved as a parameterized type.
public class Foo<T> {
void foo(Foo<@Bar T> this) {}
public static void main(String[] args) {
assert Foo.class.getDeclaredMethod("foo").getAnnotatedReceiverType() instanceof AnnotatedParameterizedType;
}
}
@raphw
raphw / Foo.java
Last active January 19, 2016 13:22
Receiver type overview
public class Foo<T> {
class Bar<S> {
Bar(Foo<T> Foo.this) {}
void bar(Foo<T>.Bar<S> this) {}
}
static class Qux<S> {
@raphw
raphw / Foo.java
Last active January 19, 2016 14:45
Illegal receiver type specification: Annotate type path.
class Foo {
class Bar {
void qux(@TypeAnnotation Foo.@TypeAnnotation Bar this) { } // Foo is treated as owner type.
}
}
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TypeAnnotation { }
@raphw
raphw / Foo.java
Last active January 20, 2016 11:08
Annotations for owner types are invers to the type navigation order.
class Foo<T> {
abstract class Bar {
// type path is not null but .
abstract void qux(@TypeAnnotation(1) Bar arg);
abstract void baz(Foo<T>.@TypeAnnotation(7) Bar arg);
}
}
@Target(Element.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@raphw
raphw / Foo.java
Last active January 21, 2016 08:47
Incorrect resolution of type annotations on nested parameterized type.
public class Foo {
public static void main(String[] args) throws Exception {
System.out.println(Arrays.asList(Foo.class.getDeclaredField("bar").getAnnotatedType().getAnnotations()));
System.out.println(Arrays.asList(Foo.class.getDeclaredField("qux").getAnnotatedType().getAnnotations()));
}
GenericNested<Void>.@TypeAnnotation Inner bar;
Nested.@TypeAnnotation Inner qux;
@raphw
raphw / BootstrapAgent.java
Last active March 6, 2025 18:06
An example agent that intercepts a method of the bootstrap class loader.
package net.bytebuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassInjector;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
@raphw
raphw / Bar.java
Last active March 2, 2016 21:04
Weak parent class loader test
public class Bar {
public static Object baz() {
return new Object();
}
}
@raphw
raphw / keybase.md
Last active February 16, 2017 22:13
keybase.md

Keybase proof

I hereby claim:

  • I am raphw on github.
  • I am raphw (https://keybase.io/raphw) on keybase.
  • I have a public key ASCRLoOS-VdPyzfuhZ_xgec5Zht5jaGp2ScPVs_qJ-kXEgo

To claim this, I am signing this object:

@raphw
raphw / Foo.java
Last active September 23, 2016 09:30
Java agent problem on J9.
public class Foo {
public static void main(String[] args) throws UnmodifiableClassException, InterruptedException {
// jar: https://bintray.com/raphw/maven/download_file?file_path=net%2Fbytebuddy%2Fbyte-buddy-agent%2F1.4.26%2Fbyte-buddy-agent-1.4.26.jar
Instrumentation instrumentation = ByteBuddyAgent.install();
System.out.println(instrumentation.isRedefineClassesSupported());
System.out.println(instrumentation.isRetransformClassesSupported());
@raphw
raphw / WeakeningAgent.java
Last active January 23, 2021 11:40
A Java agent for fixing exports for an app that is not yet Java 9 aware.
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Layer;
import java.lang.reflect.Module;
import java.util.*;
public class WeakeningAgent {
public static void premain(String argument, Instrumentation instrumentation) {
boolean full = argument != null && argument.equals("full");
Set<Module> importing = new HashSet<>(), exporting = new HashSet<>();