{"record":{"id":"7953fec56202ecd3","repo":"material-components/material-components-android","slug":"non-color-resource-found-name-name-typeid-typ","errorCode":null,"errorMessage":"Non color resource found: name={name}, typeId={typeId}","messagePattern":"Non color resource found: name=(.+?), typeId=(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/color/ColorResourcesTableCreator.java","lineNumber":87,"sourceCode":"    if (colorMapping.entrySet().isEmpty()) {\n      throw new IllegalArgumentException(\"No color resources provided for harmonization.\");\n    }\n    PackageInfo applicationPackageInfo =\n        new PackageInfo(APPLICATION_PACKAGE_ID, context.getPackageName());\n\n    Map<PackageInfo, List<ColorResource>> colorResourceMap = new HashMap<>();\n    ColorResource colorResource = null;\n    for (Map.Entry<Integer, Integer> entry : colorMapping.entrySet()) {\n      colorResource =\n          new ColorResource(\n              entry.getKey(),\n              context.getResources().getResourceEntryName(entry.getKey()),\n              entry.getValue());\n      if (!context\n          .getResources()\n          .getResourceTypeName(entry.getKey())\n          .equals(RESOURCE_TYPE_NAME_COLOR)) {\n        throw new IllegalArgumentException(\n            \"Non color resource found: name=\"\n                + colorResource.name\n                + \", typeId=\"\n                + Integer.toHexString(colorResource.typeId & 0xFF));\n      }\n      PackageInfo packageInfo;\n      if (colorResource.packageId == ANDROID_PACKAGE_ID) {\n        packageInfo = ANDROID_PACKAGE_INFO;\n      } else if (colorResource.packageId == APPLICATION_PACKAGE_ID) {\n        packageInfo = applicationPackageInfo;\n      } else {\n        throw new IllegalArgumentException(\n            \"Not supported with unknown package id: \" + colorResource.packageId);\n      }\n      if (!colorResourceMap.containsKey(packageInfo)) {\n        colorResourceMap.put(packageInfo, new ArrayList<ColorResource>());\n      }\n      colorResourceMap.get(packageInfo).add(colorResource);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/color/ColorResourcesTableCreator.java#L69-L105","documentation":"While iterating the color mapping, the creator resolves each resource ID's type name via Resources.getResourceTypeName and requires it to be 'color'. Any ID of another type (string, dimen, drawable) is rejected with IllegalArgumentException including the offending name and type id, because the generated table can only remap color entries.","triggerScenarios":"Passing a non-color resource ID in the colorOverride map, e.g. R.string.primary or R.dimen.spacing, instead of R.color.primary; building the map from generic resource keys parsed from config; ID collisions after refactoring a resource from color to drawable.","commonSituations":"Server-driven theming where keys are resource names resolved with getIdentifier and mis-typed; refactors that changed a color resource into a drawable (e.g. color -> gradient) without updating the override map.","solutions":["Fix the mapping so every key is a genuine color resource (values/colors.xml entries, R.color.*).","If resolving names dynamically with getIdentifier, verify defType is \"color\" before adding to the map.","Remove or map-to-resource-ids entries that no longer reference colors after a refactor."],"exampleFix":"// before\nval overrides = mapOf(R.string.brand_color to R.color.new_color) // wrong type, throws\n\n// after\nval overrides = mapOf(R.color.brand_color to R.color.new_color)","handlingStrategy":"validation","validationCode":"fun Map<Int, Int>.filterColorResources(context: Context): Map<Int, Int> =\n    filterKeys { id ->\n      context.resources.getResourceTypeName(id) == \"color\"\n    }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use R.color.* ids as keys of override maps.","When resolving by name with getIdentifier, always pass defType=\"color\" and check for 0.","Re-run the map builder after moving resources between res/ folders."],"tags":["android","material-components","dynamic-color","resources","type-mismatch"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}