Skip to content

Commit

Permalink
Supports dynamic subclasses of types with no package
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Dec 2, 2022
1 parent f40488d commit 281c99d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improved error message output for objects that throw exceptions in their `toString()` methods. ([Issue 716](https://github.com/jqno/equalsverifier/issues/716))

### Fixed

- Fix `ClassFormatError` when attempting to create a dynamic subclass for a class that has no package. ([Issue 638](https://github.com/jqno/equalsverifier/issues/638))

## [3.12] - 2022-11-30

### Added
Expand Down
Expand Up @@ -86,7 +86,7 @@ public static synchronized <S> Class<S> giveDynamicSubclass(
String namePrefix = isSystemClass ? FALLBACK_PACKAGE_NAME : getPackageName(superclass);
String name =
namePrefix +
"." +
(namePrefix.isEmpty() ? "" : ".") +
superclass.getSimpleName() +
"$$DynamicSubclass$" +
Integer.toHexString(superclass.hashCode()) +
Expand Down
Expand Up @@ -7,7 +7,9 @@

import java.lang.reflect.Field;
import java.util.List;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import nl.jqno.equalsverifier.testhelpers.types.ColorBlindColorPoint;
import nl.jqno.equalsverifier.testhelpers.types.FinalPoint;
import nl.jqno.equalsverifier.testhelpers.types.Point;
Expand Down Expand Up @@ -104,4 +106,16 @@ class Super {}
Field f = sub.getDeclaredField("dynamicField");
assertNotNull(f);
}

@Test
public void giveDynamicSubclassForClassWithNoPackage() {
Class<?> type = new ByteBuddy()
.with(TypeValidation.DISABLED)
.subclass(Object.class)
.name("NoPackage")
.make()
.load(getClass().getClassLoader())
.getLoaded();
Instantiator.giveDynamicSubclass(type, "X", b -> b);
}
}

0 comments on commit 281c99d

Please sign in to comment.