Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 124187 Details for
Bug 259435
[compiler] No compiler error/warning for invalid encoding in Java source files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_259435.txt (text/plain), 3.92 KB, created by
Olivier Thomann
on 2009-01-29 14:12:37 EST
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2009-01-29 14:12:37 EST
Size:
3.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/util/Util.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v >retrieving revision 1.127 >diff -u -r1.127 Util.java >--- model/org/eclipse/jdt/internal/core/util/Util.java 9 Jan 2009 23:01:35 -0000 1.127 >+++ model/org/eclipse/jdt/internal/core/util/Util.java 29 Jan 2009 19:10:53 -0000 >@@ -12,6 +12,16 @@ > > import java.io.*; > import java.net.URI; >+import java.nio.ByteBuffer; >+import java.nio.CharBuffer; >+import java.nio.charset.Charset; >+import java.nio.charset.CharsetDecoder; >+import java.nio.charset.CoderResult; >+import java.nio.charset.CodingErrorAction; >+import java.nio.charset.IllegalCharsetNameException; >+import java.nio.charset.MalformedInputException; >+import java.nio.charset.UnmappableCharacterException; >+import java.nio.charset.UnsupportedCharsetException; > import java.util.*; > import java.util.zip.ZipEntry; > import java.util.zip.ZipFile; >@@ -74,7 +84,6 @@ > * Provides convenient utility methods to other types in this package. > */ > public class Util { >- > public interface Comparable { > /** > * Returns 0 if this and c are equal, >0 if this is greater than c, >@@ -1113,25 +1122,6 @@ > } > > public static char[] getResourceContentsAsCharArray(IFile file, String encoding) throws JavaModelException { >- // Get file length >- // workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=130736 by using java.io.File if possible >- IPath location = file.getLocation(); >- long length; >- if (location == null) { >- // non local file >- try { >- URI locationURI = file.getLocationURI(); >- if (locationURI == null) >- throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Messages.bind(Messages.file_notFound, file.getFullPath().toString()))); >- length = EFS.getStore(locationURI).fetchInfo().getLength(); >- } catch (CoreException e) { >- throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); >- } >- } else { >- // local file >- length = location.toFile().length(); >- } >- > // Get resource contents > InputStream stream= null; > try { >@@ -1140,7 +1130,7 @@ > throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); > } > try { >- return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, (int) length, encoding); >+ return getInputStreamAsCharArray(file, stream, encoding); > } catch (IOException e) { > throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); > } finally { >@@ -1152,6 +1142,30 @@ > } > } > >+ public static char[] getInputStreamAsCharArray(IFile file, InputStream inputStream, String encoding) throws IOException { >+ Charset charset = null; >+ String defaultEncoding = encoding == null ? System.getProperty("file.encoding") : encoding; //$NON-NLS-1$ >+ try { >+ charset = Charset.forName(defaultEncoding); >+ } catch (IllegalCharsetNameException e) { >+ System.err.println("Illegal charset name : " + defaultEncoding); //$NON-NLS-1$ >+ return null; >+ } catch(UnsupportedCharsetException e) { >+ System.err.println("Unsupported charset : " + defaultEncoding); //$NON-NLS-1$ >+ return null; >+ } >+ byte[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(inputStream, -1); >+ CharsetDecoder charsetDecoder = charset.newDecoder(); >+ ByteBuffer byteBuffer = ByteBuffer.allocate(contents.length); >+ byteBuffer.put(contents); >+ byteBuffer.flip(); >+ charsetDecoder.onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); >+ CharBuffer out = charsetDecoder.decode(byteBuffer); >+ if (out.hasArray()) { >+ return out.array(); >+ } >+ return String.valueOf(out).toCharArray(); >+ } > /* > * Returns the signature of the given type. > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 259435
:
120993
| 124187