-
Notifications
You must be signed in to change notification settings - Fork 164
Description
Problem
I today found a case where I think ECJ can avoid emitting The type X cannot be resolved. It is indirectly referenced from required type
Take this example project:
now remove from the manifest these imports:
https://github.com/eclipse-equinox/equinox/blob/2fd1eb7b348f3a3925b60f0c33dafeb6feae4b9a/bundles/org.eclipse.equinox.jsp.jasper.registry/META-INF/MANIFEST.MF#L13-L14
And you will get this error then
Description Resource Path Location Type
The type javax.servlet.http.HttpServlet cannot be resolved. It is indirectly referenced from required type org.eclipse.equinox.jsp.jasper.JspServlet JSPFactory.java /org.eclipse.equinox.jsp.jasper.registry/src/org/eclipse/equinox/jsp/jasper/registry line 1 Java Problem
One would argue that this is unavoidable because JspServlet extends HttpServlet so the compiler must know the type., but interestingly if you change this line
from public Object create() to public JspServlet create() it works! This shows another issue here, the error is actually shown at the top of the file but the error obviously is related to the return type of the method, so I would have expected it to be shown at line 58!
Current behavior
As far as I understand the reason for this is that ECJ wants to check that the return type is compatible, so it needs to check JspServlet, all its super classes and implemented interfaces and then discovers that it can not see the extended type HttpServlet.
Expected behavior
As every class must extend Object there is no need to further check if return types are compatible. It would even valuable to first check if the Type itself already implements any compatible class or interface already, but I do not know if that maybe already happens.
Impact
Currently users are forced to import unused packages. Also when writing code one sometimes hit this issue and it is very annoying to then need to find out what to do to make the compiler happy, and even PDEs Quick-fix currently can not help here as there is no trace anywhere that javax.servlet.http is needed at all.
So summary:
- Error is shown at wrong line
- the type
HttpServletis actually not needed here as regardless of what this type looks like it must extend Object and is compatible.