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 should specify what constitutes a "suitable constructor" #2390

Open
jerseyrobot opened this issue Sep 27, 2013 · 6 comments
Open

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

jerseyrobot opened this issue Sep 27, 2013 · 6 comments

Comments

@jerseyrobot
Copy link
Contributor

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]

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Reported by cowwoc

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
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.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
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.

@jerseyrobot
Copy link
Contributor Author

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

@jerseyrobot
Copy link
Contributor Author

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

@jerseyrobot
Copy link
Contributor Author

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

No branches or pull requests

1 participant