Skip to content

Commit

Permalink
Fix Class initialization must not depend on services error on Intel…
Browse files Browse the repository at this point in the history
…liJ 2024.2 EAP
  • Loading branch information
PawelLipski committed Jul 19, 2024
1 parent 48c3999 commit d48785a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<JavaMethodCall>("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("<clinit>");
}
})
.because("class initialization must not depend on services since IntelliJ 2024.2")
.check(productionClasses);
}

@Test
public void no_classes_should_call_Collections_nCopies() {
noClasses()
Expand Down

0 comments on commit d48785a

Please sign in to comment.