Skip to content

[master] Support integer values for float fields in structured configurable variables#44567

Open
warunalakshitha wants to merge 5 commits into
ballerina-platform:masterfrom
warunalakshitha:int_values_to_float_configs
Open

[master] Support integer values for float fields in structured configurable variables#44567
warunalakshitha wants to merge 5 commits into
ballerina-platform:masterfrom
warunalakshitha:int_values_to_float_configs

Conversation

@warunalakshitha
Copy link
Copy Markdown
Contributor

@warunalakshitha warunalakshitha commented Apr 23, 2026

Purpose

Fixes #44565

Approach

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

Samples

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

Remarks

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

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

This pull request updates TOML configuration parsing to accept integer numeric literals for fields declared as float in structured configurable variables and to improve decimal handling, preventing runtime type violations and increasing configuration flexibility.

Problem Addressed
Structured configurable record fields typed as float were rejected at runtime when TOML configuration provided integer literals (e.g., price = 12), causing an InherentTypeViolation.

Solution Implemented

  • Adjusted TOML-to-Ballerina conversion so float-typed fields use Number.doubleValue(), allowing TOML integer literals to be interpreted as floats.
  • Improved decimal parsing to construct BigDecimal in a type-aware way (handling integral TOML values directly and falling back to string/number conversions) instead of assuming Double instances.
  • Added integration tests and TOML fixtures (Cricketer record with numeric fields) and updated unit test expectations to validate integer-to-float acceptance and robust decimal handling.

Impact
Configurations can now use integer literals for float-typed fields and provide numeric values for decimal-typed fields without causing runtime type errors, reducing configuration failures and improving usability of structured configurables.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

TOML numeric-to-Ballerina conversion now distinguishes float and decimal sources (uses Number.doubleValue() for floats and type-aware BigDecimal construction for decimals). Adds a new Cricketer readonly record, configurable declaration, TOML fixtures (structured and inline), and updated tests to validate mixed int/float/large-integer inputs.

Changes

Cricketer configurables + numeric conversion

Layer / File(s) Summary
Data Shape
.../configRecordType/types.bal
Adds type Cricketer readonly & record with fields: name, strikeRate, battingAverage, bowlingAverage, bowlingEconomy, largeDecimalAverage.
Configurable Declaration & Tests
.../configRecordType/records.bal
Adds configurable Cricketer cricketer = ?; and updates testRecords() to assert field values and runtime types (battingAverage as float; bowling fields and largeDecimalAverage as decimal).
Config Fixtures
.../Config_records.toml, .../Config_records_inline.toml
Adds [cricketer] structured section and cricketer = { ... } inline record containing mixed integer and floating numeric literals including a large integer for decimal testing.
Core Implementation
.../ConfigValueCreator.java, .../TomlProvider.java
Updates FLOAT_TAG handling to use Number.doubleValue() and decimal handling to construct BigDecimal in a type-aware way (special-case Long, otherwise use toString/new BigDecimal).
Tests & TOML fixtures
.../ConfigTest.java, .../TomlProviderTest.java, .../ArrayConfig.toml, .../MapTypeConfig.toml, .../SimpleTypesConfig.toml
Adjusts test expectations and test TOML data to reflect integer-literal decimals vs float-literal decimals (e.g., 4 vs 4.5, 32 vs 32.94, split decimalVar and decimalVarFloat).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled TOML numbers by moonlight,

Turned ints to doubles, kept decimals tight,
Cricketers’ stats now fit the score,
Floats and BigDecimals play once more,
Hopping home with configs bright ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete: it references the issue but lacks details on Approach, Samples, and Remarks; all checklist items are unchecked, indicating missing implementation details. Fill in the Approach section explaining the implementation strategy, add Samples showing the fix, and complete or remove the checklist items appropriately before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: support for integer values in float fields of structured configurable variables, directly addressing the issue being fixed.
Linked Issues check ✅ Passed The code changes fully address issue #44565 by implementing conversions for TOML integer values to float/decimal types in structured configurables, with comprehensive test coverage added.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the integer-to-float conversion for structured configurable variables; no extraneous modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java`:
- Line 328: The DECIMAL_TAG branch in ConfigValueCreator currently casts
tomlValue to Double which fails when Utils.checkEffectiveTomlType allowed an
INTEGER (Long); update the DECIMAL_TAG case to handle both Long and Double (and
any existing BigDecimal) by checking tomlValue's runtime type and creating the
BigDecimal accordingly (e.g., BigDecimal.valueOf((Long) tomlValue) for Long,
BigDecimal.valueOf((Double) tomlValue) for Double, or using the value directly
if already a BigDecimal) before calling ValueCreator.createDecimalValue; also
add a test for a decimal field populated with an integer TOML literal to prevent
regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f61e54c1-076d-4606-ba3d-6f62c8d1ff4a

📥 Commits

Reviewing files that changed from the base of the PR and between f59068a and 96411d2.

📒 Files selected for processing (5)
  • bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records_inline.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/records.bal
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/types.bal

@warunalakshitha warunalakshitha marked this pull request as draft April 23, 2026 08:42
@warunalakshitha warunalakshitha marked this pull request as ready for review April 27, 2026 10:50
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java`:
- Around line 328-331: The decimal conversion currently loses precision by
always calling ((Number) tomlValue).doubleValue() before constructing
BigDecimal; update the TypeTags.DECIMAL_TAG branch in ConfigValueCreator (and
mirror the same change in TomlProvider.getAsDecimalAndMark) to inspect the
runtime type of tomlValue and construct the BigDecimal from the most exact
representation: if tomlValue is a Long (or Integer/Short) use
BigDecimal.valueOf(((Number) tomlValue).longValue()), if it is a BigInteger use
new BigDecimal((BigInteger) tomlValue), otherwise fall back to
BigDecimal.valueOf(((Number) tomlValue).doubleValue()) for floating inputs;
ensure you then pass that BigDecimal into ValueCreator.createDecimalValue so
large integers keep exact precision.

In
`@bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java`:
- Around line 243-244: The decimal conversion in TomlProvider uses
BigDecimal.valueOf(((Number) value).doubleValue()) which loses precision for
large integral Numbers; update the conversion in TomlProvider so it constructs
the BigDecimal from the integral representation instead of from double: if value
is a Long (or Integer) use BigDecimal.valueOf(((Number) value).longValue()), if
it can be a BigInteger use new BigDecimal((BigInteger) value), otherwise fall
back to new BigDecimal(value.toString()); then call
getTomlConfigValue(ValueCreator.createDecimalValue(decimalValue), key). Also add
a unit test binding a large integer TOML literal (e.g. 2^53+1) to a configurable
decimal to prevent regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9db79d2-cb11-4db1-ad2d-cdbea1ea6675

📥 Commits

Reviewing files that changed from the base of the PR and between 96411d2 and 427f31d.

📒 Files selected for processing (6)
  • bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java
  • bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records_inline.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/records.bal
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/types.bal
✅ Files skipped from review due to trivial changes (2)
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/types.bal
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records_inline.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/records.bal

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.02%. Comparing base (3211861) to head (6d525b8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #44567      +/-   ##
============================================
- Coverage     75.03%   75.02%   -0.01%     
- Complexity    58707    58711       +4     
============================================
  Files          3601     3601              
  Lines        227161   227168       +7     
  Branches      29581    29583       +2     
============================================
+ Hits         170443   170444       +1     
- Misses        47215    47218       +3     
- Partials       9503     9506       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@warunalakshitha warunalakshitha force-pushed the int_values_to_float_configs branch from 249eed9 to 6d525b8 Compare May 11, 2026 08:46
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java`:
- Around line 243-249: The getAsFloatAndMark() path in TomlProvider still
returns raw Long for integer TOML numbers causing inconsistent behavior with
decimal coercion; in TomlProvider.update the getAsFloatAndMark() implementation
should detect numeric values that are instances of Long (or integer types) and
convert them to Double (e.g., via Double.valueOf(((Long) value).doubleValue())
or creating a BFloat/BValue equivalent) before returning, mirroring the
BigDecimal coercion used in the decimal accessor (see
ValueCreator.createDecimalValue and getTomlConfigValue for reference); also add
a simple-provider regression test that loads a plain configurable float (e.g., x
= 12) to ensure it resolves as a float/double and include it alongside the new
TOML numeric tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ca3b43b-94bb-4de6-b298-3f4ee234318c

📥 Commits

Reviewing files that changed from the base of the PR and between 249eed9 and 6d525b8.

📒 Files selected for processing (11)
  • bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java
  • bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java
  • bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/config/ConfigTest.java
  • bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/config/TomlProviderTest.java
  • bvm/ballerina-runtime/src/test/resources/config_files/ArrayConfig.toml
  • bvm/ballerina-runtime/src/test/resources/config_files/MapTypeConfig.toml
  • bvm/ballerina-runtime/src/test/resources/config_files/SimpleTypesConfig.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records_inline.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/records.bal
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/types.bal
✅ Files skipped from review due to trivial changes (4)
  • bvm/ballerina-runtime/src/test/resources/config_files/ArrayConfig.toml
  • bvm/ballerina-runtime/src/test/resources/config_files/SimpleTypesConfig.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records_inline.toml
  • bvm/ballerina-runtime/src/test/resources/config_files/MapTypeConfig.toml
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/Config_records.toml
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/records.bal
  • tests/jballerina-integration-test/src/test/resources/configurables/configStructuredTypesProject/configRecordType/types.bal

Comment on lines +243 to +249
BigDecimal decimalValue;
if (value instanceof Long) {
decimalValue = BigDecimal.valueOf((Long) value);
} else {
decimalValue = new BigDecimal(value.toString());
}
return getTomlConfigValue(ValueCreator.createDecimalValue(decimalValue), key);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Simple configurable float still misses the same int→float coercion.

This fixes the decimal accessor, but the sibling getAsFloatAndMark() path still returns the raw TOML number. Since integer TOML literals already pass float type validation, a plain configurable float with x = 12 will still resolve as Long instead of Double, so the behavior is now inconsistent between simple and structured configurables. Please normalize that path too and add a simple-provider regression case alongside the new TOML numeric tests.

Suggested follow-up
`@Override`
public Optional<ConfigValue> getAsFloatAndMark(Module module, VariableKey key) {
    Object value = getPrimitiveTomlValue(module, key);
    if (value == null) {
        return Optional.empty();
    }
-    return getTomlConfigValue(value, key);
+    return getTomlConfigValue(((Number) value).doubleValue(), key);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java`
around lines 243 - 249, The getAsFloatAndMark() path in TomlProvider still
returns raw Long for integer TOML numbers causing inconsistent behavior with
decimal coercion; in TomlProvider.update the getAsFloatAndMark() implementation
should detect numeric values that are instances of Long (or integer types) and
convert them to Double (e.g., via Double.valueOf(((Long) value).doubleValue())
or creating a BFloat/BValue equivalent) before returning, mirroring the
BigDecimal coercion used in the decimal accessor (see
ValueCreator.createDecimalValue and getTomlConfigValue for reference); also add
a simple-provider regression test that loads a plain configurable float (e.g., x
= 12) to ensure it resolves as a float/double and include it alongside the new
TOML numeric tests.

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.

[Bug]: InherentTypeViolation when assigning int values to float fields in structured configurables

1 participant