Skip to content

Fix crash when formatting method references #1630

Merged
bulldozer-bot[bot] merged 1 commit intodevelopfrom
cr/unexpected
Mar 26, 2026
Merged

Fix crash when formatting method references #1630
bulldozer-bot[bot] merged 1 commit intodevelopfrom
cr/unexpected

Conversation

@crogoz
Copy link
Copy Markdown
Contributor

@crogoz crogoz commented Mar 24, 2026

Before this PR

Internal thread here
Formatting code containing a method reference whose qualifier is a simple method call (e.g. getModificationContext()::getRestrictionStatusOrDefault) threw:

<File>.java:LINE_UNDEFINED palantir-java-format(java.lang.IllegalStateException) Didn't find expected break at the beginning of level. (...)
  Resolve these lints or suppress with `suppressLintsFor`

This happened because CountWidthUntilBreakVisitor.visitLevel — which computes how wide a prefix is before its first break — assumed all levels either had a special inlineability hint or started with nested Level objects. A simple method call starts with a Token, which matched neither case and fell through to a throw.

After this PR

The fallback instead walks the level's docs, summing their widths until the first Break.

==COMMIT_MSG==
Fix crash when formatting method references
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link
Copy Markdown

changelog-app Bot commented Mar 24, 2026

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Fix crash when formatting method references

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link
Copy Markdown

changelog-app Bot commented Mar 24, 2026

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

🐛 Fixes

  • Fix crash when formatting method references (#1630)

something = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2
+ 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2
+ 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;
return StreamEx.of(itemsToCreate)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this diff

Copy link
Copy Markdown
Contributor Author

@crogoz crogoz Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this in the input, the output is in A.output, previously it was failing at this line. The tests are making sure that formatting A.input will result in A.output

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is A.output no? I suppose I didn't understand the diff because it didn't look like there was anything different? But you're basically saying the equivalent of: assertThatCode(...).doesNotThrow()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, exactly!

@bulldozer-bot bulldozer-bot Bot merged commit f7453db into develop Mar 26, 2026
7 checks passed
@bulldozer-bot bulldozer-bot Bot deleted the cr/unexpected branch March 26, 2026 14:49
@autorelease3
Copy link
Copy Markdown

autorelease3 Bot commented Mar 26, 2026

Released 2.90.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants