Bug 66480 Selecting a badly encoded file in the package explorer results in MalformedInputExceptions
I200406091200 - Create a folder with UTF-8 encoding - Have some .java files in the folder that are Latin1 encoded, but with their encoding not set (they inherit from the folder, UTF-8) (-> these files cannot be opened, which is correct) - Selecting the file in the package explorer without opening it Observe the exceptions below (actually many more, as all refactoring actions are updated). The same happens when dragging a correctly encoded file over one of the bad files, e.g. when using drag&drop refactoring. The package explorer should handle this more gracefully. !ENTRY org.eclipse.jdt.ui 4 10001 Jun 10, 2004 12:18:03.825 !MESSAGE Internal Error !STACK 1 org.eclipse.jdt.core.JavaModelException[985]: sun.io.MalformedInputException at java.lang.Throwable.<init>(Throwable.java) at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java) at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(StreamDecoder.java) at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java) at java.io.InputStreamReader.read(InputStreamReader.java) at org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(Util.java) at org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(Util.java) at org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(Util.java) at org.eclipse.jdt.internal.core.CompilationUnit.openBuffer(CompilationUnit.java:1029) at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:102) at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:183) at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getChildren(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getChildrenOfType(JavaElement.java) at org.eclipse.jdt.internal.core.CompilationUnit.getTypes(CompilationUnit.java:822) at org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil.getMainType(JavaElementUtil.java) at org.eclipse.jdt.ui.actions.UseSupertypeAction.getSingleSelectedType(UseSupertypeAction.java:114) at org.eclipse.jdt.ui.actions.UseSupertypeAction.canEnable(UseSupertypeAction.java:103) at org.eclipse.jdt.ui.actions.UseSupertypeAction.selectionChanged(UseSupertypeAction.java:81) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged(SelectionDispatchAction.java) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1388) at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:694) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:720) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:180) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:175) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1362) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1333) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:252) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:334) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:272) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60) at java.lang.reflect.Method.invoke(Method.java:391) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:638) at org.eclipse.core.launcher.Main.main(Main.java:622) Caused by: sun.io.MalformedInputException at java.lang.Throwable.<init>(Throwable.java) at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java) at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(StreamDecoder.java) at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java) at java.io.InputStreamReader.read(InputStreamReader.java) at org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(Util.java) at org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(Util.java) at org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(Util.java) at org.eclipse.jdt.internal.core.CompilationUnit.openBuffer(CompilationUnit.java:1029) at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:102) at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:183) at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getChildren(JavaElement.java) at org.eclipse.jdt.internal.core.JavaElement.getChildrenOfType(JavaElement.java) at org.eclipse.jdt.internal.core.CompilationUnit.getTypes(CompilationUnit.java:822) at org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil.getMainType(JavaElementUtil.java) at org.eclipse.jdt.ui.actions.UseSupertypeAction.getSingleSelectedType(UseSupertypeAction.java:114) at org.eclipse.jdt.ui.actions.UseSupertypeAction.canEnable(UseSupertypeAction.java:103) at org.eclipse.jdt.ui.actions.UseSupertypeAction.selectionChanged(UseSupertypeAction.java:81) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged(SelectionDispatchAction.java) at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java) at org.eclipse.core.runtime.Platform.run(Platform.java) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:157) at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1388) at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:694) at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:720) at org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenStrategy.java:180) at org.eclipse.jface.util.OpenStrategy.access$3(OpenStrategy.java:175) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1362) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1333) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:252) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141) at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96) at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:334) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:272) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60) at java.lang.reflect.Method.invoke(Method.java:391) at org.eclipse.core.launcher.Main.basicRun(Main.java:185) at org.eclipse.core.launcher.Main.run(Main.java:638) at org.eclipse.core.launcher.Main.main(Main.java:622)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FormatAllAction.java
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.ui.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.filebuffers.FileBuffers;