fix ReadAccessAllowed exception from indices when converting bytes to string representation (IDEADEV-29274)

This commit is contained in:
Eugene Zhuravlev
2008-08-21 18:03:51 +04:00
parent d90e0ead54
commit 9da3c0408c
2 changed files with 28 additions and 7 deletions
@@ -842,6 +842,7 @@ public class FileBasedIndex implements ApplicationComponent {
private void markDirty(final VirtualFileEvent event) {
iterateIndexableFiles(event.getFile(), new Processor<VirtualFile>() {
public boolean process(final VirtualFile file) {
FileContent fileContent = null;
for (ID<?, ?> indexId : myIndices.keySet()) {
if (getInputFilter(indexId).acceptInput(file)) {
if (myNeedContentLoading.contains(indexId)) {
@@ -849,7 +850,10 @@ public class FileBasedIndex implements ApplicationComponent {
}
else {
try {
updateSingleIndex(indexId, file, new FileContent(file, (byte[])null), null);
if (fileContent == null) {
fileContent = new FileContent(file, (byte[])null);
}
updateSingleIndex(indexId, file, fileContent, null);
}
catch (StorageException e) {
LOG.info(e);
@@ -877,6 +881,7 @@ public class FileBasedIndex implements ApplicationComponent {
if (SingleRootFileViewProvider.isTooLarge(file)) return;
final List<ID<?, ?>> affectedIndices = new ArrayList<ID<?, ?>>(myIndices.size());
FileContent fileContent = null;
for (ID<?, ?> indexId : myIndices.keySet()) {
if (shouldUpdateIndex(file, indexId)) {
if (myNeedContentLoading.contains(indexId)) {
@@ -885,7 +890,10 @@ public class FileBasedIndex implements ApplicationComponent {
else {
// invalidate it synchronously
try {
updateSingleIndex(indexId, file, null, new FileContent(file, (byte[])null));
if (fileContent == null) {
fileContent = new FileContent(file, (byte[])null);
}
updateSingleIndex(indexId, file, null, fileContent);
}
catch (StorageException e) {
LOG.info(e);
@@ -1061,10 +1069,14 @@ public class FileBasedIndex implements ApplicationComponent {
break;
}
}
FileContent fileContent = null;
for (ID<?, ?> indexId : mySkipContentLoading) {
if (shouldIndexFile(file, indexId)) {
try {
updateSingleIndex(indexId, file, new FileContent(file, (byte[])null), null);
if (fileContent == null) {
fileContent = new FileContent(file, (byte[])null);
}
updateSingleIndex(indexId, file, fileContent, null);
}
catch (StorageException e) {
LOG.info(e);
@@ -1,6 +1,5 @@
package com.intellij.util.indexing;
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.vfs.VirtualFile;
@@ -16,6 +15,7 @@ public final class FileContent {
private final VirtualFile myFile;
private final String fileName;
private final FileType myFileType;
private final Charset myCharset;
private byte[] myContent;
private CharSequence myContentAsText = null;
@@ -44,6 +44,7 @@ public final class FileContent {
fileName = file.getName();
myContent = content;
myContentAsText = contentAsText;
myCharset = file.getCharset();
}
public VirtualFile getFile() {
@@ -54,12 +55,15 @@ public final class FileContent {
return fileName;
}
public Charset getCharset() {
return myCharset;
}
public byte[] getContent() {
if (myContent == null) {
if (myContentAsText != null) {
try {
final Charset charset = myFile.getCharset();
myContent = charset != null? myContentAsText.toString().getBytes(charset.name()) : myContentAsText.toString().getBytes();
myContent = myCharset != null? myContentAsText.toString().getBytes(myCharset.name()) : myContentAsText.toString().getBytes();
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
@@ -75,7 +79,12 @@ public final class FileContent {
}
if (myContentAsText == null) {
if (myContent != null) {
myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myFile, false);
try {
myContentAsText = new String(myContent, myCharset.name());
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
return myContentAsText;