didi/DoKit · error · RuntimeException
failed to get size
Error message
failed to get size
What it means
Same fail-fast guard as the horizontal variant, but in VerticalDividerItemDecoration.getDividerSize: it needs a divider WIDTH for outRect.set(0, 0, size, 0) and throws RuntimeException when no mPaintProvider, mSizeProvider, or mDrawableProvider is set. Note the vertical variant has no mSpaceProvider branch, so a space provider alone will NOT satisfy it. Thrown during RecyclerView layout as soon as getItemOffsets runs.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/toolpanel/decoration/VerticalDividerItemDecoration.java:209
@Override
protected void setItemOffsets(Rect outRect, int position, RecyclerView parent) {
if (mPositionInsideItem) {
outRect.set(0, 0, 0, 0);
return;
}
outRect.set(0, 0, getDividerSize(position, parent), 0);
}
private int getDividerSize(int position, RecyclerView parent) {
if (mPaintProvider != null) {
return (int) mPaintProvider.dividerPaint(position, parent).getStrokeWidth();
} else if (mSizeProvider != null) {
return mSizeProvider.dividerSize(position, parent);
} else if (mDrawableProvider != null) {
Drawable drawable = mDrawableProvider.drawableProvider(position, parent);
return drawable.getIntrinsicWidth();
}
throw new RuntimeException("failed to get size");
}
/**
* Interface for controlling divider margin
*/
public interface MarginProvider {
/**
* Returns top margin of divider.
*
* @param position Divider position (or group index for GridLayoutManager)
* @param parent RecyclerView
* @return top margin
*/
int dividerTopMargin(int position, RecyclerView parent);
/**
* Returns bottom margin of divider.View on GitHub (pinned to 626827cddb)
Solutions
- Set a size provider before build(): .sizeProvider((position, parent) -> dividerWidthPx)
- Or use the common one-liner .drawable(drawableRes) / .drawableProvider(...) so getIntrinsicWidth() is used
- Do not rely on spaceProvider here — the vertical decoration has no space branch; use size or drawable/paint provider
- Remove the decoration entirely if no divider is wanted
Example fix
// before
recyclerView.addItemDecoration(new VerticalDividerItemDecoration.Builder(this).build());
// after
recyclerView.addItemDecoration(
new VerticalDividerItemDecoration.Builder(this)
.sizeProvider((position, parent) -> Math.round(1 * getResources().getDisplayMetrics().density))
.build()); Defensive patterns
Strategy: validation
Validate before calling
// Always configure a size source for the vertical divider.
VerticalDividerItemDecoration deco = new VerticalDividerItemDecoration.Builder(context)
.sizeProvider((position, parent) -> Math.round(1 * context.getResources().getDisplayMetrics().density))
.build();
recyclerView.addItemDecoration(deco); Try / catch
try {
recyclerView.addItemDecoration(deco);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("failed to get size")) {
Log.w(TAG, "Vertical divider lacks size/drawable provider; skipping", e);
} else throw e;
} Prevention
- Remember the vertical variant has NO spaceProvider branch — size, drawable, or paint provider required
- Do not assume marginProvider sets thickness; it only sets insets
- Keep divider builders centralized in one utility so the provider is never forgotten
When it happens
Trigger: new VerticalDividerItemDecoration.Builder(context).build() with zero provider setters; or setting only a marginProvider (which controls insets, not size); or porting code from the horizontal decoration that relied on spaceProvider.
Common situations: Copy-pasting divider setup between list layouts where the vertical one lost its size/drawable provider; assuming marginProvider determines thickness.
Related errors
- failed to get size
- Use setColor method of Paint class to specify line color. Do
- Use setStrokeWidth method of Paint class to specify line siz
- maxStoredHeapDumps must be at least 1
- Cannot set the LeakDirectoryProvider after it has already be
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/6b336bfd4c6f6516.
Report an issue: GitHub.