Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

UnsupportedOperationException removing patterns from sealed class with lexical preservation #4830

Open
@steinybot

Description

@steinybot
importorg.junit.jupiter.api.Test;importcom.github.javaparser.JavaParser;importcom.github.javaparser.ast.expr.InstanceOfExpr;importcom.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;publicclassJavaParserBugsTest {@TestvoidtestUnsupportedOperationExceptionRemovingPattern() {varparser =newJavaParser();varcu =parser.parse("""                        public class PatternMatching_UnsupportedOperationException {                            public void processObject(Object obj) {                                if (obj instanceof String s) {                                    System.out.println(s);                                }                            }                        }                        """).getResult().orElseThrow();LexicalPreservingPrinter.setup(cu);cu.findAll(InstanceOfExpr.class).forEach(InstanceOfExpr::removePattern);    }}

Fails with:

NodeText: NodeText{[ChildTextElement{obj}, " "   <1>   (line 3,col 16)-(line 3,col 16), "instanceof"   <37>   (line 3,col 17)-(line 3,col 26), " "   <1>   (line 3,col 27)-(line 3,col 27), ChildTextElement{String}, ChildTextElement{String s}]}. Difference: Difference{[Kept{child(NameExpr)}, Kept{CsmToken(property: )}, Kept{CsmToken(property:instanceof)}, Kept{CsmToken(property: )}, Kept{child(ClassOrInterfaceType)}]} ChildTextElement{String s}java.lang.UnsupportedOperationException: NodeText: NodeText{[ChildTextElement{obj}, " "   <1>   (line 3,col 16)-(line 3,col 16), "instanceof"   <37>   (line 3,col 17)-(line 3,col 26), " "   <1>   (line 3,col 27)-(line 3,col 27), ChildTextElement{String}, ChildTextElement{String s}]}. Difference: Difference{[Kept{child(NameExpr)}, Kept{CsmToken(property: )}, Kept{CsmToken(property:instanceof)}, Kept{CsmToken(property: )}, Kept{child(ClassOrInterfaceType)}]} ChildTextElement{String s}at com.github.javaparser.printer.lexicalpreservation.Difference.applyLeftOverOriginalElements(Difference.java:416)at com.github.javaparser.printer.lexicalpreservation.Difference.apply(Difference.java:379)at com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.calculatePropertyChange(LexicalDifferenceCalculator.java:181)at com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter$Observer.concretePropertyChange(LexicalPreservingPrinter.java:204)at com.github.javaparser.ast.observer.PropagatingAstObserver.propertyChange(PropagatingAstObserver.java:64)at com.github.javaparser.ast.Node.lambda$notifyPropertyChange$7(Node.java:675)at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)at com.github.javaparser.ast.Node.notifyPropertyChange(Node.java:675)at com.github.javaparser.ast.expr.InstanceOfExpr.setPattern(InstanceOfExpr.java:269)at com.github.javaparser.ast.expr.InstanceOfExpr.removePattern(InstanceOfExpr.java:225)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp