Skip to content

Fix crash when a formatter XML references a color resource - #134

Merged
halfhp merged 3 commits into
masterfrom
fix-88-color-resource-refs
Sep 7, 2026
Merged

Fix crash when a formatter XML references a color resource#134
halfhp merged 3 commits into
masterfrom
fix-88-color-resource-refs

Conversation

@halfhp

@halfhp halfhp commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Fixes #88

Cause

Formatter XML such as linePaint.color="@color/accent_blue" crashed with IllegalArgumentException: Unknown color. AAPT2 compiles that reference to the form @2131034163, and Fig's parseIntAttr passed any value starting with @ straight to Color.parseColor, which only understands hex and named colors. The 2019 comment on the issue said this would be fixed in Fig for 1.5.8, but the fix never landed: figlib 1.0.11 on Maven Central still has the bug.

Fix

  • parseIntAttr now resolves @ values as resource references and reads them by resource type: color yields the color value, dimen the pixel size, anything else the integer. Both the compiled @<id> form and the @color/name string form are handled.
  • Negative integers are now accepted too; they previously fell through to Color.parseColor as well.
  • An unresolvable reference throws an IllegalArgumentException naming the value, instead of the opaque "Unknown color".

Fig folded into androidplot-core

Fig (com.halfhp.fig:figlib) is a three-file library by the same author whose only known consumer is Androidplot, and whose publishing pipeline is defunct. Its sources and test now live in com.androidplot.util.fig, under the SPDX header. Callers in Plot, Formatter and XYRegionFormatter are rewired, and the external dependency is gone from the published POM, which now lists only androidx.annotation. Nothing in Androidplot's public API exposed Fig types.

Documentation

  • New docs/xml_configuration.md describes the property-path syntax, accepted value types (including resource references), the androidPlot. layout prefix, and the ProGuard requirement. Adapted from Fig's README in Androidplot terms.
  • The quickstart's two links to the external Fig repo now point at that page; the index links it from the XML Attributes section.
  • docs/release_notes.md gains a 1.5.12 entry covering this fix, the Fig merge, the SDK 37 toolchain and snapshot publishing.

Verification

  • New FigTest cases cover a color reference, an integer reference, hex color, negative int and an unresolvable reference. The reference cases fail on the old logic and pass on the fix (checked both ways).
  • Fig's original FigTest cases pass after the move.
  • Full suite: 211 tests, 0 failures. Lint, coverage report, core release AAR and demoapp debug build all pass.
  • The demoapp's line_point_formatter.xml now references a color resource, and aapt2 dump xmltree confirms it compiles to a reference. It's used by the Animated XY Plot and FX Plot examples, so those screens act as a live regression check.

halfhp and others added 3 commits September 6, 2026 22:31
Fig's parseIntAttr handed any value starting with '@' to
Color.parseColor, which only understands hex and named colors, so a
formatter XML with linePaint.color="@color/foo" crashed with "Unknown
color". Resolve the reference instead and read it by resource type:
colors yield the color value, dimens the pixel size, anything else the
integer. Also accept negative integers, which previously fell through
to Color.parseColor as well.

Fig was a separate library (com.halfhp.fig:figlib) whose only consumer
is Androidplot and whose publishing pipeline is defunct, so its three
sources and test are folded into com.androidplot.util.fig and the
external dependency is dropped from the published POM.

The demoapp's line_point_formatter now references a color resource as
a live regression check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWySSrgd1L761915n3mFoo
The quickstart linked to the external Fig repo for the configuration
syntax; now that Fig is part of androidplot-core, document the syntax
in docs/xml_configuration.md, link it from the quickstart and index,
and note the #88 fix and toolchain changes in the release notes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWySSrgd1L761915n3mFoo
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BWySSrgd1L761915n3mFoo
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 66.25767% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.16%. Comparing base (47c23df) to head (3be3ce4).

Files with missing lines Patch % Lines
...re/src/main/java/com/androidplot/util/fig/Fig.java 63.90% 33 Missing and 15 partials ⚠️
...c/main/java/com/androidplot/util/fig/FigUtils.java 82.14% 3 Missing and 2 partials ⚠️
...in/java/com/androidplot/util/fig/FigException.java 0.00% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #134      +/-   ##
============================================
- Coverage     69.26%   69.16%   -0.10%     
- Complexity     1199     1233      +34     
============================================
  Files           106      109       +3     
  Lines          4997     5160     +163     
  Branches        512      537      +25     
============================================
+ Hits           3461     3569     +108     
- Misses         1210     1248      +38     
- Partials        326      343      +17     

☔ View full report in Codecov by Harness.
📢 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.

@halfhp
halfhp merged commit c16a720 into master Sep 7, 2026
1 check passed
@halfhp
halfhp deleted the fix-88-color-resource-refs branch September 7, 2026 03:53
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.

Android Plot crashes when setting color from resource id

2 participants