diff --git a/CHANGE-NOTES.md b/CHANGE-NOTES.md index 601e8fb21..69096bc70 100644 --- a/CHANGE-NOTES.md +++ b/CHANGE-NOTES.md @@ -3,6 +3,7 @@ ## v5.0.1 - Improved: performance of loading repositories with long git histories and a lot of red-edge branches +- Fixed: `Class initialization must not depend on services` error on IntelliJ 2024.2 EAP (reported by @fan-tom) ## v5.0.0 - Added support for IntelliJ 2024.2. diff --git a/frontend/ui/impl/src/main/java/com/virtuslab/gitmachete/frontend/ui/impl/cell/BranchOrCommitCellRendererComponent.java b/frontend/ui/impl/src/main/java/com/virtuslab/gitmachete/frontend/ui/impl/cell/BranchOrCommitCellRendererComponent.java index 50e16a324..cfdeba346 100644 --- a/frontend/ui/impl/src/main/java/com/virtuslab/gitmachete/frontend/ui/impl/cell/BranchOrCommitCellRendererComponent.java +++ b/frontend/ui/impl/src/main/java/com/virtuslab/gitmachete/frontend/ui/impl/cell/BranchOrCommitCellRendererComponent.java @@ -68,9 +68,6 @@ public final class BranchOrCommitCellRendererComponent extends SimpleColoredRend private static final String CELL_TEXT_FRAGMENTS_SPACING = " "; private static final String HEAVY_WIDE_HEADED_RIGHTWARDS_ARROW = "\u2794"; - private static final IGraphCellPainterFactory graphCellPainterFactoryInstance = ApplicationManager.getApplication() - .getService(IGraphCellPainterFactory.class); - private final JTable graphTable; private final BufferedImage graphImage; private final MyTableCellRenderer myTableCellRenderer; @@ -104,7 +101,7 @@ public BranchOrCommitCellRendererComponent( } this.graphImage = getGraphImage(graphTable, maxGraphNodePositionInRow); Graphics2D g2 = graphImage.createGraphics(); - val graphCellPainter = graphCellPainterFactoryInstance.create(table); + val graphCellPainter = ApplicationManager.getApplication().getService(IGraphCellPainterFactory.class).create(table); graphCellPainter.draw(g2, renderParts); this.myTableCellRenderer = new MyTableCellRenderer(); diff --git a/src/test/java/com/virtuslab/archunit/ForbiddenMethodsTestSuite.java b/src/test/java/com/virtuslab/archunit/ForbiddenMethodsTestSuite.java index bac74e59b..e51382b5b 100644 --- a/src/test/java/com/virtuslab/archunit/ForbiddenMethodsTestSuite.java +++ b/src/test/java/com/virtuslab/archunit/ForbiddenMethodsTestSuite.java @@ -7,6 +7,9 @@ import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; +import com.tngtech.archunit.base.DescribedPredicate; +import com.tngtech.archunit.core.domain.JavaMethodCall; +import lombok.val; import org.junit.jupiter.api.Test; import com.virtuslab.gitmachete.backend.impl.GitMacheteRepositorySnapshot; @@ -25,6 +28,24 @@ public void no_classes_should_call_AnActionEvent_getRequiredData() { .check(productionClasses); } + @Test + public void no_classes_should_call_Application_getService_from_static_initializer() { + noClasses() + .should() + .callMethodWhere(new DescribedPredicate("Application#getService is called from static initializer") { + @Override + public boolean test(JavaMethodCall javaMethodCall) { + val target = javaMethodCall.getTarget(); + val origin = javaMethodCall.getOrigin(); + return target.getOwner().isEquivalentTo(com.intellij.openapi.application.Application.class) + && target.getName().equals("getService") + && origin.getName().equals(""); + } + }) + .because("class initialization must not depend on services since IntelliJ 2024.2") + .check(productionClasses); + } + @Test public void no_classes_should_call_Collections_nCopies() { noClasses()