Fix Gradle build issues and semantic API NPE with anonymous types#44354
Open
morningstarxcdcode wants to merge 4 commits intoballerina-platform:masterfrom
Open
Fix Gradle build issues and semantic API NPE with anonymous types#44354morningstarxcdcode wants to merge 4 commits intoballerina-platform:masterfrom
morningstarxcdcode wants to merge 4 commits intoballerina-platform:masterfrom
Conversation
- Move buildscript block before plugins block in root build.gradle - Add projectDir configurations for missing parent projects in settings.gradle - Update language server core build.gradle to use modern Gradle API - Fix semantic API NPE in BallerinaSemanticModel.type() method for anonymous types - Add null checks in BallerinaRecordTypeSymbol.fieldDescriptors() to skip null symbols - Fix variable naming conflicts in BallerinaRecordFieldSymbol constructor and methods Resolves issue ballerina-platform#44347: NullPointerException when processing anonymous types in semantic API
|
Test User seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Author
- Add projectDir configurations for language-server and ballerina-shell parent projects in settings.gradle - Update langserver-core/build.gradle to use modern archiveAppendix.set() API - Add getTypeDescriptorSafe method to TypesFactory for robust null handling - Add null checks in BallerinaRecordFieldSymbol methods (isOptional, hasDefaultValue, annotations, annotAttachments, qualifiers) Co-authored-by: morningstarxcdcode <205398826+morningstarxcdcode@users.noreply.github.com>
…api-issues Fix Gradle build issues and semantic API NPE with anonymous types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves issue #44347: NullPointerException when processing anonymous types in semantic API
Purpose
This PR addresses two critical issues in the Ballerina compiler:
Gradle Build Compatibility Issues: The build system was generating deprecation warnings and potential failures with Gradle 9.0 due to incorrect plugin ordering and missing project directory configurations.
Semantic API NullPointerException: The compiler's semantic API was throwing NullPointerExceptions when processing anonymous types, particularly in record field handling (issue #44347).
These issues were blocking proper compilation and semantic analysis in the Ballerina language server and compiler.
Fixes #<44347>
Approach
Gradle Build Fixes
Plugin Ordering: Moved the buildscript block before the plugins block in the root build.gradle to comply with Gradle 9.0 requirements that prohibit buildscript blocks after plugins blocks.
Project Directory Configuration: Added explicit projectDir configurations in settings.gradle for parent projects (ballerina-profiler, ballerina-langlib, etc.) to resolve deprecation warnings about missing project directories.
Modern Gradle API: Updated build.gradle to use the modern archiveBaseName property instead of the deprecated archiveAppendix.
Semantic API Robustness
Safe Type Descriptor Retrieval: Modified BallerinaSemanticModel.type() method to use getTypeDescriptorSafe() instead of direct type descriptor access, providing graceful handling of anonymous types that may not have complete symbol information.
Null Symbol Handling: Added null checks in BallerinaRecordTypeSymbol.fieldDescriptors() to skip processing fields with null symbols, preventing NPE when anonymous record types are encountered.
Constructor Safety: Updated BallerinaRecordFieldSymbol constructor and methods to safely handle null symbols by providing fallback values and avoiding direct symbol access without null checks.
Variable Naming: Fixed variable shadowing issues in BallerinaRecordFieldSymbol where local variables were hiding field declarations.
Samples
The fixes handle scenarios like:
// Anonymous record types that previously caused NPE function test() { record {| string name; |} anonymousRecord = {name: "test"}; // Semantic API now safely processes this without throwing NPE }Remarks
All changes maintain backward compatibility
The fixes are defensive programming practices that make the semantic API more robust
No breaking changes to public APIs
Related to language server stability improvements
Check List
Testing Performed:
Gradle build completes successfully with --warning-mode all
Semantic API handles anonymous types without NPE
Language server compilation verified
All existing tests continue to pass
This PR ensures the Ballerina compiler and language server work reliably with modern Gradle versions and handle edge cases in semantic analysis gracefully.