Skip to content

Comments

Fix Gradle build issues and semantic API NPE with anonymous types#44354

Open
morningstarxcdcode wants to merge 4 commits intoballerina-platform:masterfrom
morningstarxcdcode:fix-gradle-build-issues-new
Open

Fix Gradle build issues and semantic API NPE with anonymous types#44354
morningstarxcdcode wants to merge 4 commits intoballerina-platform:masterfrom
morningstarxcdcode:fix-gradle-build-issues-new

Conversation

@morningstarxcdcode
Copy link

@morningstarxcdcode morningstarxcdcode commented Oct 12, 2025

  • 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 #44347: NullPointerException when processing anonymous types in semantic API

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

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

Describe how you are implementing the solutions along with the design details.

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

Provide high-level details about the samples related to this feature.

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

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

  • 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

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples
Screenshot 2025-10-12 at 1 24 47 PM

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.

Test User and others added 2 commits October 12, 2025 13:22
- 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
@CLAassistant
Copy link

CLAassistant commented Oct 12, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ morningstarxcdcode
❌ Test User
❌ Copilot


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.

@morningstarxcdcode
Copy link
Author

#44347

Copilot AI and others added 2 commits October 12, 2025 08:02
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants