mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle] fix NPE when restoring serialized cached data IDEA-202843
This commit is contained in:
+7
-4
@@ -355,9 +355,10 @@ public class ProjectDataManagerImpl implements ProjectDataManager {
|
||||
if (Boolean.TRUE.equals(startNode.getUserData(DATA_READY))) return;
|
||||
final DeduplicateVisitorsSupplier supplier = new DeduplicateVisitorsSupplier();
|
||||
ExternalSystemApiUtil.visit(startNode, dataNode -> {
|
||||
prepareDataToUse(dataNode);
|
||||
dataNode.visitData(supplier.getVisitor(dataNode.getKey()));
|
||||
dataNode.putUserData(DATA_READY, Boolean.TRUE);
|
||||
if (prepareDataToUse(dataNode)) {
|
||||
dataNode.visitData(supplier.getVisitor(dataNode.getKey()));
|
||||
dataNode.putUserData(DATA_READY, Boolean.TRUE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -428,7 +429,7 @@ public class ProjectDataManagerImpl implements ProjectDataManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareDataToUse(@NotNull DataNode dataNode) {
|
||||
private boolean prepareDataToUse(@NotNull DataNode dataNode) {
|
||||
final Map<Key<?>, List<ProjectDataService<?, ?>>> servicesByKey = myServices.getValue();
|
||||
List<ProjectDataService<?, ?>> services = servicesByKey.get(dataNode.getKey());
|
||||
if (services != null) {
|
||||
@@ -438,8 +439,10 @@ public class ProjectDataManagerImpl implements ProjectDataManager {
|
||||
catch (Exception e) {
|
||||
LOG.debug(e);
|
||||
dataNode.clear(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void commit(@NotNull final IdeModifiableModelsProvider modelsProvider,
|
||||
|
||||
+32
-1
@@ -5,12 +5,15 @@ import com.intellij.openapi.externalSystem.model.DataNode;
|
||||
import com.intellij.openapi.externalSystem.model.Key;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData;
|
||||
import com.intellij.openapi.externalSystem.model.project.*;
|
||||
import com.intellij.openapi.externalSystem.service.project.ExternalLibraryPathTypeMapperImpl;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
|
||||
import com.intellij.openapi.externalSystem.test.ExternalSystemTestUtil;
|
||||
import com.intellij.openapi.externalSystem.util.Order;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -55,6 +58,34 @@ public class ProjectDataManagerImplTest extends PlatformTestCase {
|
||||
"removeDataAfter");
|
||||
}
|
||||
|
||||
public void testBrokenDataNodePreparation() {
|
||||
final LibraryDependencyData data = new LibraryDependencyData(new ModuleData("id",
|
||||
ExternalSystemTestUtil.TEST_EXTERNAL_SYSTEM_ID,
|
||||
"typeId",
|
||||
"module_name",
|
||||
"fake_path",
|
||||
"fake_path"),
|
||||
new LibraryData(ExternalSystemTestUtil.TEST_EXTERNAL_SYSTEM_ID,
|
||||
"library_name"),
|
||||
LibraryLevel.PROJECT);
|
||||
|
||||
final DataNode<LibraryDependencyData> badNode =
|
||||
new DataNode<LibraryDependencyData>(ProjectKeys.LIBRARY_DEPENDENCY, data, null) {
|
||||
@Override
|
||||
public void prepareData(@NotNull ClassLoader... loaders) {
|
||||
// mock a node that failed to deserialize it's data.
|
||||
ReflectionUtil.resetField(this, "myData");
|
||||
throw new RuntimeException("Broken node can not be prepared properly");
|
||||
}
|
||||
};
|
||||
|
||||
new ProjectDataManagerImpl(
|
||||
new LibraryDependencyDataService(
|
||||
new LibraryDataService(
|
||||
new ExternalLibraryPathTypeMapperImpl())))
|
||||
.ensureTheDataIsReadyToUse(badNode);
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
static class RunAfterTestDataService extends TestDataService {
|
||||
static class MyObject {
|
||||
|
||||
Reference in New Issue
Block a user