Skip to content

fix(FunctionalInterfaceLogic): return empty() for non-reference types (#3625)#5022

Merged
jlerbsc merged 1 commit into
javaparser:masterfrom
jlerbsc:master
May 24, 2026
Merged

fix(FunctionalInterfaceLogic): return empty() for non-reference types (#3625)#5022
jlerbsc merged 1 commit into
javaparser:masterfrom
jlerbsc:master

Conversation

@jlerbsc

@jlerbsc jlerbsc commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Fixes #3625.

getFunctionalMethod(ResolvedType) called asReferenceType() unconditionally,
throwing UnsupportedOperationException when the type was not a reference type
(e.g. ResolvedArrayType, ResolvedPrimitiveType).
Per JLS §9.8, a functional interface is always an interface, which is a
reference type. Arrays and primitives can therefore never be functional
interfaces, so returning Optional.empty() for them is semantically correct.
Fix: move the isReferenceType() guard to the top of the method, before any
call to asReferenceType(). The now-redundant isReferenceType() condition on
the inner if-statement is removed as a consequence.
Add two regression tests covering ResolvedPrimitiveType and ResolvedArrayType
to prevent future regressions.

@codecov

codecov Bot commented May 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.701%. Comparing base (a4ef5de) to head (2c5d41f).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ser/resolution/logic/FunctionalInterfaceLogic.java 0.000% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #5022       +/-   ##
===============================================
- Coverage     58.704%   58.701%   -0.003%     
  Complexity      2592      2592               
===============================================
  Files            702       702               
  Lines          40222     40224        +2     
  Branches        7329      7329               
===============================================
  Hits           23612     23612               
- Misses         13639     13641        +2     
  Partials        2971      2971               
Flag Coverage Δ
AlsoSlowTests 58.701% <0.000%> (-0.003%) ⬇️
javaparser-core 58.701% <0.000%> (-0.003%) ⬇️
javaparser-symbol-solver 58.701% <0.000%> (-0.003%) ⬇️
jdk-10 58.271% <0.000%> (-0.003%) ⬇️
jdk-11 58.270% <0.000%> (-0.003%) ⬇️
jdk-12 58.273% <0.000%> (-0.003%) ⬇️
jdk-13 58.273% <0.000%> (-0.003%) ⬇️
jdk-14 58.504% <0.000%> (-0.001%) ⬇️
jdk-15 58.504% <0.000%> (-0.003%) ⬇️
jdk-16 58.479% <0.000%> (-0.003%) ⬇️
jdk-17 58.628% <0.000%> (-0.003%) ⬇️
jdk-18 58.626% <0.000%> (-0.006%) ⬇️
jdk-8 58.110% <0.000%> (-0.001%) ⬇️
jdk-9 58.271% <0.000%> (-0.003%) ⬇️
macos-latest 58.676% <0.000%> (-0.003%) ⬇️
ubuntu-latest 58.671% <0.000%> (-0.003%) ⬇️
windows-latest 58.683% <0.000%> (-0.003%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ser/resolution/logic/FunctionalInterfaceLogic.java 0.000% <0.000%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d27561...2c5d41f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jlerbsc jlerbsc merged commit 2e56ea6 into javaparser:master May 24, 2026
62 of 64 checks passed
@jlerbsc jlerbsc added this to the next release milestone May 24, 2026
@jlerbsc jlerbsc added the PR: Fixed A PR that offers a fix or correction label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Fixed A PR that offers a fix or correction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter type of getFunctionalMethod too narrow

1 participant