Skip to content

Commit

Permalink
Merge pull request dropwizard#4587 from rhowe/deprecated-javaversion
Browse files Browse the repository at this point in the history
Register resources in the same way for Java 8 and 11
  • Loading branch information
jplock authored Jan 26, 2022
2 parents dd6a892 + 473fba9 commit b9edce7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.dropwizard.jersey.params.AbstractParamConverterProvider;
import io.dropwizard.jersey.sessions.SessionFactoryProvider;
import io.dropwizard.jersey.validation.FuzzyEnumParamConverterProvider;
import io.dropwizard.util.JavaVersion;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.LoaderClassPath;
Expand All @@ -29,6 +28,7 @@
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -163,12 +163,7 @@ public ResourceConfig register(final Object component) {
pool.insertClassPath(new LoaderClassPath(this.getClass().getClassLoader()));
final CtClass cc = pool.makeClass(SpecificBinder.class.getName() + UUID.randomUUID());
cc.setSuperclass(pool.get(SpecificBinder.class.getName()));
final Object binderProxy;
if (JavaVersion.isJava8()) {
binderProxy = cc.toClass().getConstructor(Object.class, Class.class).newInstance(object, clazz);
} else {
binderProxy = cc.toClass(SpecificBinder.class).getConstructor(Object.class, Class.class).newInstance(object, clazz);
}
final Object binderProxy = cc.toClass(MethodHandles.lookup()).getConstructor(Object.class, Class.class).newInstance(object, clazz);
super.register(binderProxy);
return super.register(clazz);
} catch (Exception e) {
Expand All @@ -185,8 +180,8 @@ static String cleanUpPath(String path) {
* @since 2.0
*/
public static class SpecificBinder extends AbstractBinder {
private Object object;
private Class<?> clazz;
private final Object object;
private final Class<?> clazz;

public SpecificBinder(Object object, Class<?> clazz) {
this.object = object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import static org.assertj.core.api.Assertions.assertThat;

class DropwizardResourceConfigTest {
private DropwizardResourceConfig rc = DropwizardResourceConfig.forTesting();
private AbstractJerseyTest jerseyTest = new AbstractJerseyTest() {
private final DropwizardResourceConfig rc = DropwizardResourceConfig.forTesting();
private final AbstractJerseyTest jerseyTest = new AbstractJerseyTest() {
@Override
protected Application configure() {
return rc;
Expand Down Expand Up @@ -437,7 +437,7 @@ public static class Customer {
}

public static class ResourceWithInjectedDependency implements ResourceInterface {
private Dependency dependency;
private final Dependency dependency;

@Inject
public ResourceWithInjectedDependency(Dependency dependency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

/**
* @since 2.0
*
* @deprecated will be removed in a future release
*/
@Deprecated
public final class JavaVersion {
private JavaVersion() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import static org.assertj.core.api.Assertions.assertThat;

/**
* @deprecated {@link JavaVersion} is deprecated
*/
@Deprecated
class JavaVersionTest {
@Test
void isJava8_returns_false_if_specVersion_cannot_be_read() {
Expand All @@ -22,4 +26,4 @@ void isJava8_returns_true_if_specVersion_is_Java_11() {
System.setProperty("java.specification.version", "11");
assertThat(JavaVersion.isJava8()).isFalse();
}
}
}

0 comments on commit b9edce7

Please sign in to comment.