question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StateNode#handleOnAttach exception message should be improved

See original GitHub issue

I ran into this exception: https://github.com/vaadin/flow/blob/907cbbd59612ac2e31daf5c1566fb48529d75200/flow-server/src/main/java/com/vaadin/flow/internal/StateNode.java#L705-L706 When you get it, the stack trace gives you no hint what this is about:

Unexpected exception occured: java.lang.IllegalStateException: Can't change id once it has been ass
igned
        at com.vaadin.flow.internal.StateNode.handleOnAttach(StateNode.java:705)
        at com.vaadin.flow.internal.StateNode.lambda$onAttach$1(StateNode.java:312)
        at com.vaadin.flow.internal.StateNode.visitNodeTreeBottomUp(StateNode.java:669)
        at com.vaadin.flow.internal.StateNode.onAttach(StateNode.java:311)
        at com.vaadin.flow.internal.StateNode.setParent(StateNode.java:270)
        at com.vaadin.flow.internal.nodefeature.NodeFeature.attachPotentialChild(NodeFeature.java:78)
        at com.vaadin.flow.internal.nodefeature.StateNodeNodeList.add(StateNodeNodeList.java:53)
        at com.vaadin.flow.internal.nodefeature.ElementChildrenList.add(ElementChildrenList.java:42)
        at com.vaadin.flow.dom.impl.AbstractNodeStateProvider.insertChild(AbstractNodeStateProvider.java:102)
        at com.vaadin.flow.dom.Node.insertChild(Node.java:250)
        at com.vaadin.flow.dom.Node.appendChild(Node.java:141)
        at com.vaadin.flow.data.provider.AbstractComponentDataGenerator.registerRenderedComponent(AbstractComponentDataGenerator.java:128)
        at com.vaadin.flow.data.provider.ComponentDataGenerator.generateData(ComponentDataGenerator.java:84)
        at com.vaadin.flow.data.provider.CompositeDataGenerator.lambda$generateData$0(CompositeDataGenerator.java:47)
        at java.lang.Iterable.forEach(Iterable.java:75)
        at com.vaadin.flow.data.provider.CompositeDataGenerator.generateData(CompositeDataGenerator.java:47)
        at com.vaadin.flow.data.provider.DataCommunicator.generateJson(DataCommunicator.java:660)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.stream.IntPipeline$4$1.accept(IntPipeline.java:250)
        at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
        at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
...

Expected behavior: it should at least tell, what kind of id is the problem.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
plekucommented, Nov 15, 2021

I tried to recreate this exception using Vaadin 14.5.1

@MathiasAugstein please note that 14.5 has been unsupported since May 2021 , I’d advice you to update to the latest minor version 14.7.

1reaction
TatuLundcommented, Nov 15, 2021

The exception is still throw in other case, but the text has been changed to give better hint, what is the likely cause so that it is easier to address the issue in application code.

"The component '"
                    + component.getClass()
                    + "' is already attached to a UI instance which differs "
                    + "from the conainer's UI instance. It means that the component instance is "
                    + "reused instead being produced every time on 'createComponent' call."
                    + " Check whether the component instance is a singleton or has inappropriate Spring scope.");

OR, logging warning

        if (renderedComponent.getParent().isPresent()) {
            LoggerFactory.getLogger(ComponentDataGenerator.class).warn(
                    "The 'createComponent' method returned a component '{}' which already has a parent."
                            + " It means that most likely your component renderer '{}' class is implemented incorrectly",
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write a good exception message
All three items in this message I can work out from the rest of the exception. I know the class and method from...
Read more >
Best Practices for exceptions - .NET - Microsoft Learn
Learn best practices for exceptions, such as using try/catch/finally, handling common conditions without exceptions, and using predefined .
Read more >
How do I give streams better exception messages?
Boost is an open source project so the way I see it there are 2 options: Complain. Either write a bug report or...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
An exception could occur during execution of an except or else clause. Again, the exception is re-raised after the finally clause has been...
Read more >
How to Raise Exceptions in Ruby - Rollbar
This method can be used to retrieve a specific exception message from a raised exception object. Raising Generic Exceptions. Like the title of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found