Skip to content

Commit

Permalink
fix: use the correct parent ClassLoader on Quarkus
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo committed Jun 28, 2023
1 parent 00ac56a commit f4b163d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@

/**
* Loads a class if we have the Gizmo-generated bytecode for it,
* otherwise the current {@link Thread}'s context {@link ClassLoader}.
* otherwise uses the current {@link Thread}'s context {@link ClassLoader}.
* This implementation is thread-safe.
*/
public final class GizmoClassLoader extends ClassLoader {

private final Map<String, byte[]> classNameToBytecodeMap = new HashMap<>();

public GizmoClassLoader() {
/*
* As parent, Gizmo needs to use the same ClassLoader that loaded its own class.
* Otherwise, issues will arise in Quarkus with MemberAccessors which were first loaded by Quarkus
* and then loaded again by Gizmo, which uses the default parent ClassLoader.
*/
super(GizmoClassLoader.class.getClassLoader());
}

@Override
public String getName() {
return "Timefold Gizmo SolutionCloner ClassLoader";
return "Timefold Solver Gizmo ClassLoader";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.Mockito.mock;

import java.lang.reflect.Member;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -109,4 +110,11 @@ void shouldUseGeneratedMemberAccessorIfExists() throws NoSuchMethodException {
assertThat(memberAccessor)
.isSameAs(mockMemberAccessor);
}

@Test
void gizmoUsesCorrectParentClassLoader() {
MemberAccessorFactory memberAccessorFactory = new MemberAccessorFactory(Collections.emptyMap());
assertThat(memberAccessorFactory.getGizmoClassLoader().getParent())
.isSameAs(memberAccessorFactory.getClass().getClassLoader());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TimefoldProcessor {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem("timefold");
return new FeatureBuildItem("timefold-solver");
}

@BuildStep
Expand Down

0 comments on commit f4b163d

Please sign in to comment.