raphw / raphw/byte-buddy

Document is hard to read

Open
#661 6 comments 2 reactions 1 assignee View on GitHub

@raphw is already working on this.

Since May 30, 2019.

documentation question
Dominant language
Java
Stars
6.9k
Forks
855
PR merge metrics
No merged PRs in 30d

Description

  1. Missing is a description of each component and its common methods (like TypePool, DynamicType, ClassLoadingStrategy etc.)
  2. Class calls may vary from version to version, such as the current version is:
package foo;
class Bar { }
class MyApplication {
  public static void main(String[] args) {
    TypePool typePool = TypePool.Default.ofClassPath();
    new ByteBuddy()
      .redefine(typePool.describe("foo.Bar").resolve(), // do not use 'Bar.class'
                ClassFileLocator.ForClassLoader.ofClassPath())
      .defineField("qux", String.class) // we learn more about defining fields later
      .make()
      .load(ClassLoader.getSystemClassLoader());
    assertThat(Bar.class.getDeclaredField("qux"), notNullValue());
  }
}

It was not compiled in 1.9.13, but the 1.9.13 version of the document could not be found. Try to change it to:

package foo;
class Bar { }
class MyApplication {
  public static void main(String[] args) {
    TypePool typePool = TypePool.Default.of(Thread.currentThread().getContextClassLoader());
    new ByteBuddy()
      .redefine(typePool.describe("foo.Bar").resolve(), // do not use 'Bar.class'
                ClassFileLocator.ForClassLoader.of(Thread.currentThread().getContextClassLoader()))
      .defineField("qux", String.class) // we learn more about defining fields later
      .make()
      .load(ClassLoader.getSystemClassLoader());
     assertThat(Bar.class.getDeclaredField("qux"), notNullValue());
  }
}

But in the end:

Exception in thread "main" java.lang.IllegalStateException: Class already loaded: foo.Bar

Much more complex than using javassist

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.