Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Jersey should specify what constitutes a "suitable constructor" #2390

Open
glassfishrobot opened this issue Sep 27, 2013 · 5 comments
Open

Comments

@glassfishrobot
Copy link

Jersey throws the following exception:

java.lang.NoSuchMethodException: Could not find a suitable constructor in com.mycompany.jersey2guice.JerseyApplication class.
	at org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:189)
[...]

Expected behavior: explain what constitutes a "suitable constructor" in the exception message so developers know what needs to get fixed. Either link to a more detailed explanation or describe it inline.

Also, it would be useful if you provided more contextual information, such as "Found constructors X, Y, Z. Was looking for A, B or C"

Affected Versions

[2.2]

@glassfishrobot
Copy link
Author

Reported by cowwoc

@glassfishrobot
Copy link
Author

cowwoc said:
Two comments:

  1. It looks like the error messages are coming from hk2 so you might have to redirect this bug report there.
  2. Please pay special attention to constructors annotated with @Inject. It is a common mistake to import com.google.Inject instead of javax.inject.Inject. Currently, org.jvnet.hk2.internal.Utilities.hasInjectAnnotation() checks for javax.inject.Inject and throws an error if two constructors are annotated with @Inject. I suggest throwing an error if a constructor is annotated with @Inject that does not resolve to javax.inject.Inject in order to help users catch errors. As far as I know, each class only uses one type of @Inject at a time so we are unlikely to run into false positives.

@glassfishrobot
Copy link
Author

sinzone said:
+1. What is a suitable constructor?

In my case the constructor in my resource/controller required some arguments, I removed them and now everything works. I guess Jersey's reflection can't initialize the class if there are some arguments, because obviously it doesn't know what to put there. This wasn't clear at a first look.

@glassfishrobot
Copy link
Author

minfrin said:
This just bit me as well, +1 on a proper error message with no weasel words.

@glassfishrobot
Copy link
Author

This issue was imported from java.net JIRA JERSEY-2118

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

No branches or pull requests

2 participants