Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey 3.1.9: java.lang.NoSuchMethodException: jakarta.inject.Inject.value() #5782

Open
mkarg opened this issue Oct 28, 2024 · 0 comments
Open

Comments

@mkarg
Copy link
Member

mkarg commented Oct 28, 2024

When bootstrapping Jersey 3.1.9 on Java SE 17 I came across this exception logged, which IMHO makes no sense to log at all:

org.glassfish.jersey.model.Parameter getValue
FINER: Unable to get the jdk.proxy2.$Proxy27 annotation value property
java.lang.NoSuchMethodException: jakarta.inject.Inject.value()
	at java.base/java.lang.Class.getMethod(Class.java:2277)
	at org.glassfish.jersey.model.Parameter.getValue(Parameter.java:452)
	at org.glassfish.jersey.model.Parameter.create(Parameter.java:269)
	at org.glassfish.jersey.server.model.Parameter.create(Parameter.java:68)
	at org.glassfish.jersey.server.model.IntrospectionModeller.checkResourceClassFields(IntrospectionModeller.java:206)
	at org.glassfish.jersey.server.model.IntrospectionModeller.doCreateResourceBuilder(IntrospectionModeller.java:118)
	at org.glassfish.jersey.server.model.IntrospectionModeller$1.call(IntrospectionModeller.java:91)
	at org.glassfish.jersey.server.model.IntrospectionModeller$1.call(IntrospectionModeller.java:88)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
	at org.glassfish.jersey.server.model.IntrospectionModeller.createResourceBuilder(IntrospectionModeller.java:88)
	at org.glassfish.jersey.server.model.Resource.from(Resource.java:781)
	at org.glassfish.jersey.server.ResourceBagConfigurator.init(ResourceBagConfigurator.java:55)
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:347)
	at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:309)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
	at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:308)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:273)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:260)
	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:310)
	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:142)

The reason for this exception is that @jakarta.inject.Inject does not have a method called value, but Jersey apparently expects to find it, as shown in the source code:

private static String getValue(Annotation a) {
try {
Method m = a.annotationType().getMethod("value");
if (m.getReturnType() != String.class) {
return null;
}
return (String) m.invoke(a);
} catch (Exception ex) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER,
String.format("Unable to get the %s annotation value property", a.getClass().getName()), ex);
}
}
return null;
}

It is not a bug nor an exceptional case that an annotation does not have a value method, so I wonder what the benefit of logging this quite normal case shall have? It is quite normal to not find that method.

BTW, as exception handling is slow in Java, it might be a performance improvement to first check the result of getMethods() before actually requesting the value method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant