NullPointerException in Studio (14.0-202) when creating Recursive/Hierarchical Property

Hi, I’m not sure if I’m doing something wrong, or there is an issue with the current release (14.0-202) of CUBA Studio, but when I create an attribute (either in code, or in the Entity designer, that is based on the current Entity (forming a hierarchical relationship), I get a NullPointerException in Studio as below.

My code looks like this:

     @OnDeleteInverse(DeletePolicy.CASCADE)
     @OnDelete(DeletePolicy.DENY)
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "PARENT_ID")
     private MyEntity parent;

     public MyEntity getParent() {
         return parent;
     }

     public void setParent(MyEntity parent) {
         this.parent = parent;
    }

Is this something that I am doing wrong, or an issue with Studio?

Thanks.

java.lang.StackOverflowError
	at com.intellij.extapi.psi.StubBasedPsiElementBase.isValid(StubBasedPsiElementBase.java:272)
	at com.intellij.psi.impl.smartPointers.SmartPsiElementPointerImpl.getElement(SmartPsiElementPointerImpl.java:91)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:851)
	at com.haulmont.studio.backend.util.MetadataUtil.ra(MetadataUtil.java:963)
	at com.haulmont.studio.backend.model.EntityPsi.getPsiClass(EntityPsi.java:465)
	at com.haulmont.studio.backend.model.EntityPsi.lambda$getFqn$15(EntityPsi.java:309)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:851)
	at com.haulmont.studio.backend.util.MetadataUtil.ra(MetadataUtil.java:963)
	at com.haulmont.studio.backend.model.EntityPsi.getFqn(EntityPsi.java:309)
	at com.haulmont.studio.backend.model.Entity.hashCode(Entity.java:493)
	at com.haulmont.studio.backend.model.View.hashCode(View.java:193)
	at java.base/java.util.Arrays.hashCode(Arrays.java:4685)
	at java.base/java.util.Objects.hash(Objects.java:146)
	...

Hi, Richard!

Unfortunately I can’t reproduce the issue.
Could you please attach idea.log file? (Help -> Show Log in Explorer)
Also a small test project in which you can reproduce the problem could also be very helpful.

I tried to recreate the issue in a new project and seemingly couldn’t, and then returned to the existing project (where I had previously commented out the offending code) and couldn’t recreate it either. It took a fair bit of head scratching to realise what was different and how to reproduce.

The issue was that I had set the name pattern to be cyclic @NamePattern("%s > %s|description,parent") which the GUI editor permitted, but is clearly unsupported. So this seems to be something that the editor should prevent, but also not crash if you do in code.

I assume that, given the error, there is no way of using the parent’s name as part of the child’s display name?

Thanks for providing all details.
The YouTrack issue was created.

You are right, parent attribute can’t be added to the name pattern. Name pattern is used to form _minimal view, but views cannot have cyclic references.
As a workaround you can store parent name in a separate attribute and update it using EntityChangedEvent each time parent changed. This attribute can be safely added to the name pattern.