Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException when using AccessibilityRenderExtension with SHRINK #1684

Open
VirtualParticle opened this issue Nov 8, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@VirtualParticle
Copy link

VirtualParticle commented Nov 8, 2024

Description
When running a test with the AccessibilityRenderExtension and the SHRINK rendering mode, the test crashes with an IllegalArgumentException

Steps to Reproduce

This test produces the error:

@get:Rule
val paparazzi = Paparazzi(
  renderExtensions = setOf(AccessibilityRenderExtension()),
  renderingMode = SessionParams.RenderingMode.SHRINK,
)

@Test
fun example() {
  paparazzi.snapshot {
    Text("Hello, world!")
  }
}
SEVERE: broken: View draw failed
java.lang.IllegalArgumentException: Layout: -84 < 0
	at android.text.Layout.<init>(Layout.java:304)
	at android.text.StaticLayout.<init>(StaticLayout.java:634)
	at android.text.StaticLayout$Builder.build(StaticLayout.java:444)
	at app.cash.paparazzi.accessibility.AccessibilityOverlayDetailsView.draw(AccessibilityOverlayDetailsView.kt:80)

The error occurs in AccessibilityOverlayDetailsView:

accessibilityElements.forEach {
  paint.color = it.color.toColorInt()
  val badge = RectF(margin, lastYCoord, margin + rectSize, lastYCoord + rectSize)
  canvas.drawRoundRect(badge, cornerRadius, cornerRadius, paint)
  canvas.save()

  val text = it.contentDescription
  val textX = badge.right + innerMargin
  val textY = badge.top
  val textLayoutWidth = (width - textX).toInt()

  val textLayout = StaticLayout.Builder
    .obtain(text, 0, text.length, textPaint, textLayoutWidth)
    .setEllipsize(TextUtils.TruncateAt.END)
    .build() // java.lang.IllegalArgumentException: Layout: -84 < 0
  canvas.save()

Expected behavior
The test should execute normally.

Additional information:

  • Paparazzi Version: 1.3.5
  • OS: MacOS and Linux
  • Compile SDK: 34
  • Gradle Version: 8.10.2
  • Android Gradle Plugin Version: 8.4.2
@VirtualParticle VirtualParticle added the bug Something isn't working label Nov 8, 2024
@savvisingh
Copy link

I have been facing the same issue, looks like there were changes in invalidPrintableChars in Snapshot class which makes some characters invalid in test name, In my case all my tests contain the invalid character, Would really like a workaround.

@jrodbx
Copy link
Collaborator

jrodbx commented Nov 11, 2024

@savvisingh aside from the commonality in throwing an instance of IllegalArgumentException, it doesn't appear that the issue you're describing is related. The breaking change is intended to avoid invalid chars from crashing on Windows platforms (#1532). Accordingly, please ensure your tests sanitize the labels and/or test method arguments.

@savvisingh
Copy link

Ah true i didn't read the whole error message before commenting, haha thanks for the reply anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants