Skip to content

No-op VMRuntime.setThreadNiceness via ASM transform#2309

Open
colinmarsch wants to merge 2 commits intomasterfrom
fix-paparazzi-layoutlib-asm-tr
Open

No-op VMRuntime.setThreadNiceness via ASM transform#2309
colinmarsch wants to merge 2 commits intomasterfrom
fix-paparazzi-layoutlib-asm-tr

Conversation

@colinmarsch
Copy link
Copy Markdown
Collaborator

@colinmarsch colinmarsch commented Mar 16, 2026

Summary

  • Fixes NoSuchMethodError: java.lang.Thread.setPosixNicenessInternal(int) introduced by the layoutlib bump
  • Layoutlib's VMRuntime.setThreadNiceness calls Thread.setPosixNicenessInternal — a Dalvik-specific native method that doesn't exist on the JVM, crashing at runtime via HandlerThread.runProcess.setThreadPriorityVMRuntime.setThreadNiceness
  • Adds a new AGP ASM instrumentation transform (ThreadNicenessVisitorFactory) that replaces the setThreadNiceness method body with a no-op return, since thread niceness is irrelevant for screenshot testing

Why

The recent layoutlib update added a code path that assumes Dalvik-specific JVM internals are available. Rather than patching at a higher level (e.g., no-oping Process.setThreadPriority), this targets the exact method that calls the missing native, preserving normal behavior elsewhere.

Layoutlib's VMRuntime.setThreadNiceness calls Thread.setPosixNicenessInternal,
a Dalvik-specific method that doesn't exist on the JVM, causing
NoSuchMethodError at runtime. Thread niceness is irrelevant for screenshot
testing, so replace the method body with a no-op return.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@saket saket left a comment

Choose a reason for hiding this comment

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

Do we already have an existing test for verifying this?

Exercises the real layoutlib VMRuntime through AGP's instrumentation
pipeline, confirming the no-op transform prevents NoSuchMethodError
on Thread.setPosixNicenessInternal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@colinmarsch
Copy link
Copy Markdown
Collaborator Author

Added an integration test in 46671bc — it exercises the real layoutlib VMRuntime through AGP's instrumentation pipeline, calling VMRuntime.getRuntime().setThreadNiceness() directly. Without the transform it fails with NoSuchMethodError: Thread.setPosixNicenessInternal.

@jrodbx jrodbx added this to the 2.0.0-alpha06 milestone Mar 17, 2026
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