Bug 18039 - Opening .class file fails
Summary: Opening .class file fails
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 enhancement (vote)
Target Milestone: 2.0 F3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-28 09:37 EDT by Debbie Wilson CLA
Modified: 2002-06-14 06:30 EDT (History)
0 users

See Also:


Attachments
log file for ArrayIndexOutOfBoundException (4.27 KB, text/plain)
2002-06-01 07:15 EDT, Claude Knaus CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Debbie Wilson CLA 2002-05-28 09:37:33 EDT
- build 20020528
- I have loaded a number of classes from the cvs repository at org.eclipse.dev 
(HEAD stream).  Among them are org.eclipse.core.runtime and 
org.eclipse.core.boot
- Search->File
- fill in "findResource(" in the 'Containing Text' field
- leave everything else as default (searching the workspace and for file name 
patterns '*')
- do the search
- I get 2 hits:
DelegatingURLClassLoader.class 
(org.eclipse.core.boot/bin/org/eclipse/core/internal/boot) and
DelegatingURLClassLoader.java
(org.eclipse.core.boot/src/org/eclipse/core/internal/boot) - 10 matches

- try to open the first file in the search result (which doesn't really make 
sense since it is a .class file)
- you get the error:

Could not open the editor

Reason:
   bin/org/eclipse/core/internal/boot does not exist

- But it does exist and there is a DelegatingURLClassLoader.class there.
- Now try to redo the search
- Search->File
- in the 'Containing Text' field you find "findResource(ΓΊ67" (i.e added 
garbage to the end of my search string).
Comment 1 Erich Gamma CLA 2002-05-28 10:25:08 EDT
This is a consequence of searching .class files. Until recently there was no 
way for search to know how to handle them, since the plugin doesn't know about 
Java.

This is now possible and we can fix this by leveraging the file type registry 
in Team (org.eclipse.team.core Team.getType(IFile file)). There are 2 options:
1) only search in files for which getType returns Team.TEXT
2) provide a settings in the File search dialog Search in binaries/Search in 
text.

My preferred solution would be 2)
Comment 2 Debbie Wilson CLA 2002-05-28 11:09:57 EDT
I'll defer to your better judgment on which solution is best.  While I can't 
currently think of a use case for wanting to search anything but files that are 
of type 'text', I'm sure my focus on this issue it too narrow.

I was really just looking for a nicer failure case here.  The directory and 
file exist but it is nonsense to try and open this file.  So why not have the 
error message tell you it can't open this file because you are trying to do 
something silly instead of telling you the directory doesn't exist (when it 
does exist)?

Of course, this assumes there is a nice way of determining that I'm being silly 
vs. the directory not existing.
Comment 3 Dani Megert CLA 2002-05-29 12:17:53 EDT
Corrected F1 to be F2
Comment 4 Dani Megert CLA 2002-05-30 06:54:15 EDT
I changed search to consider only non-binary files when doing text search but
file search will still report non-binaries.

The error message (file does not exist)  will still appear for such files. This
error message is a general bug: note that you will get the same error message
when clicking on a hand-made class file in the Navigator or Packages view.

==> Changing summary and moving to editor component: an exception (see below)
occurs when opening the file with the ClassFileEditor.

Note there are two different scenarios which both fail in a different way:
0) Create file x.class (make a text file, add "test", rename to x.class)
1) Place x.class file outside the build path
   ==> A dialog informs that the file does not exist - nothing else happens
2) Place x.class file into a package (src folder setup)
   ==> Dialog "Error, Unable to create part: x.class" appears. After clicking OK
the editor is opened but only shows/contains: "An error has occurred when
creating this editor"


Thread [main] (Suspended (exception org.eclipse.jdt.core.JavaModelException))
	org.eclipse.jdt.internal.core.PackageFragmentRoot.openWhenClosed(org.eclipse.core.runtime.IProgressMonitor) line: 352
	org.eclipse.jdt.internal.core.PackageFragment(org.eclipse.jdt.internal.core.Openable).openParent(org.eclipse.core.runtime.IProgressMonitor) line: 378
	org.eclipse.jdt.internal.core.PackageFragment(org.eclipse.jdt.internal.core.Openable).openWhenClosed(org.eclipse.core.runtime.IProgressMonitor) line: 394
	org.eclipse.jdt.internal.core.ClassFile(org.eclipse.jdt.internal.core.Openable).openParent(org.eclipse.core.runtime.IProgressMonitor) line: 378
	org.eclipse.jdt.internal.core.ClassFile(org.eclipse.jdt.internal.core.Openable).openWhenClosed(org.eclipse.core.runtime.IProgressMonitor) line: 394
	org.eclipse.jdt.internal.core.ClassFile(org.eclipse.jdt.internal.core.JavaElement).openHierarchy() line: 523
	org.eclipse.jdt.internal.core.ClassFile(org.eclipse.jdt.internal.core.JavaElement).getElementInfo() line: 310
	org.eclipse.jdt.internal.core.ClassFile(org.eclipse.jdt.internal.core.Openable).getBuffer() line: 197
	org.eclipse.jdt.internal.core.ClassFile.getSource() line: 281
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider.setDocumentContent(org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorInput, java.lang.String) line: 171
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider(org.eclipse.ui.editors.text.StorageDocumentProvider).createDocument(java.lang.Object) line: 170
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider.createDocument(java.lang.Object) line: 204
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider.createElementInfo(java.lang.Object) line: 235
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider(org.eclipse.ui.texteditor.AbstractDocumentProvider).connect(java.lang.Object) line: 277
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor(org.eclipse.ui.texteditor.AbstractTextEditor).doSetInput(org.eclipse.ui.IEditorInput) line: 1574
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor(org.eclipse.ui.texteditor.StatusTextEditor).doSetInput(org.eclipse.ui.IEditorInput) line: 160
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor(org.eclipse.jdt.internal.ui.javaeditor.JavaEditor).doSetInput(org.eclipse.ui.IEditorInput) line: 546
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor.doSetInput(org.eclipse.ui.IEditorInput) line: 468
	org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor(org.eclipse.ui.texteditor.AbstractTextEditor).init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) line: 1190
	org.eclipse.ui.internal.EditorManager.createSite(org.eclipse.ui.IEditorPart,
org.eclipse.ui.internal.registry.EditorDescriptor, org.eclipse.ui.IEditorInput)
line: 538
	org.eclipse.ui.internal.EditorManager.openInternalEditor(org.eclipse.ui.IEditorReference, org.eclipse.ui.internal.registry.EditorDescriptor, org.eclipse.ui.IEditorInput, boolean) line: 587
	org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(org.eclipse.ui.IEditorReference, org.eclipse.ui.internal.registry.EditorDescriptor, org.eclipse.ui.IEditorInput) line: 404
	org.eclipse.ui.internal.EditorManager.openEditorFromInput(org.eclipse.ui.IEditorReference, org.eclipse.ui.IFileEditorInput, boolean) line: 295
	org.eclipse.ui.internal.EditorManager.openEditor(java.lang.String,
org.eclipse.ui.IEditorInput, boolean) line: 377
	org.eclipse.ui.internal.WorkbenchPage.openEditor(org.eclipse.ui.IEditorInput,
java.lang.String, boolean, boolean, org.eclipse.core.resources.IFile) line: 1703
	org.eclipse.ui.internal.WorkbenchPage.openEditor(org.eclipse.core.resources.IFile, java.lang.String, boolean) line: 1614
	org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(org.eclipse.core.resources.IFile, boolean) line: 126
	org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(java.lang.Object, boolean) line: 99
	org.eclipse.jdt.internal.ui.actions.OpenActionUtil.open(java.lang.Object,
boolean) line: 52
	org.eclipse.jdt.ui.actions.OpenAction.run(java.lang.Object[]) line: 171
	org.eclipse.jdt.ui.actions.OpenAction.run(org.eclipse.jface.viewers.IStructuredSelection) line: 160
	org.eclipse.jdt.ui.actions.OpenAction(org.eclipse.jdt.ui.actions.SelectionDispatchAction).dispatchRun(org.eclipse.jface.viewers.ISelection) line: 178
	org.eclipse.jdt.ui.actions.OpenAction(org.eclipse.jdt.ui.actions.SelectionDispatchAction).run() line: 156
	org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(org.eclipse.jface.viewers.OpenEvent) line: 321
	org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$5.open(org.eclipse.jface.viewers.OpenEvent) line: 297
	org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer(org.eclipse.jface.viewers.StructuredViewer).fireOpen(org.eclipse.jface.viewers.OpenEvent) line: 320
	org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer(org.eclipse.jface.viewers.StructuredViewer).handleOpen(org.eclipse.swt.events.SelectionEvent) line: 494
	org.eclipse.jface.viewers.StructuredViewer$3.handleOpen(org.eclipse.swt.events.SelectionEvent) line: 581
	org.eclipse.jface.util.OpenStrategy.fireOpenEvent(org.eclipse.swt.events.SelectionEvent) line: 198
	org.eclipse.jface.util.OpenStrategy.access$2(org.eclipse.jface.util.OpenStrategy,
org.eclipse.swt.events.SelectionEvent) line: 195
	org.eclipse.jface.util.OpenStrategy$1.mouseSelectItem(org.eclipse.swt.events.SelectionEvent) line: 327
	org.eclipse.jface.util.OpenStrategy$1.handleEvent(org.eclipse.swt.widgets.Event)
line: 277
	org.eclipse.swt.widgets.EventTable.sendEvent(org.eclipse.swt.widgets.Event) line: 75
	org.eclipse.swt.widgets.Tree(org.eclipse.swt.widgets.Widget).sendEvent(org.eclipse.swt.widgets.Event) line: 825
	org.eclipse.swt.widgets.Display.runDeferredEvents() line: 1527
	org.eclipse.swt.widgets.Display.readAndDispatch() line: 1289
	org.eclipse.ui.internal.Workbench.runEventLoop() line: 1095
	org.eclipse.ui.internal.Workbench.run(java.lang.Object) line: 1078
	org.eclipse.core.internal.boot.InternalBootLoader.run(java.lang.String,
java.net.URL, java.lang.String, java.lang.String[], java.lang.Runnable) line: 739
	org.eclipse.core.boot.BootLoader.run(java.lang.String, java.net.URL,
java.lang.String, java.lang.String[]) line: 432
	EclipseRuntimeLauncher.main(java.lang.String[]) line: 24

Comment 5 Claude Knaus CLA 2002-06-01 07:13:35 EDT
fixed 1) by outputting more meaningful dialog.

passing down to jdt.core for 2) An ArrayIndexOutOfBoundException is thrown 
instead of a JavaModelException.
Comment 6 Claude Knaus CLA 2002-06-01 07:15:21 EDT
Created attachment 1159 [details]
log file for ArrayIndexOutOfBoundException
Comment 7 Philipe Mulet CLA 2002-06-03 11:03:18 EDT
Added protection to ClassFileReader (which did not protect from format issue 
when reading header).

Fixed
Comment 8 Olivier Thomann CLA 2002-06-04 14:13:32 EDT
Verified.
Comment 9 David Audel CLA 2002-06-14 06:30:46 EDT
Verified.