Community
Participate
Working Groups
Eclipse 2.1 This might be an expected/valid result but looks wrong to me: public interface A { public B getB(); } public interface B {} class X { public A getA() { return getA_in_X(); } private A getA_in_X() { return new A() { public B getB() { return getB_in_X(); } }; } private B getB_in_X() { return new B(); } } The compiler complains that getB_in_X() is never used.
I cannot reproduce on your testcase. Also note I had to tweak the following code to get it to compile. private B getB_in_X() { return new B(){}; // added anonymous }
OK, I might have missed something (I haven't really tried that on Eclipse - sorry). Here is a more concrete example: import java.io.ByteArrayInputStream; import java.io.InputStream; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IStorageEditorInput; public class X { public X() { getEditorInput(); } /** * Returns an empty storage. */ private IStorage getStorage() { return new IStorage() { public InputStream getContents() throws CoreException { return new ByteArrayInputStream("".getBytes()); } public IPath getFullPath() { return null; } public String getName() { return null; } public boolean isReadOnly() { return false; } public Object getAdapter(Class adapter) { return null; } }; } private IEditorInput getEditorInput() { return new IStorageEditorInput() { public IStorage getStorage() throws CoreException { return getStorage(); } public boolean exists() { return false; } public ImageDescriptor getImageDescriptor() { return null; } public String getName() { return null; } public IPersistableElement getPersistable() { return null; } public String getToolTipText() { return null; } public Object getAdapter(Class adapter) { return null; } }; } }
X.getStorage() is indeed unused, since the invocation buried in: public IStorage getStorage() throws CoreException { return getStorage(); } is recursively calling itself. If you want to target X.getStorage(), then it should use 'X.this.getStorage();'. Is it ok or am I missing something obvious ?
oooppsss... It seems that I was missing something obvious. :-) The funny thing is that it works during runtime.
Or you sure it doesn't perform an infinite recursion ?
Yes, I'm sure. I was using J9 - not sure if that makes a difference. I do not have the code in my workspace anymore but I can get that back if you want.
Wait... I might be wrong. I might have never tried running the code like that. Now I recall that I did have the X.this.getStorage() in my code to get rid of the warning. You're right. Please close this bug and don't tell anyone about it!!! ;-)
Closing