Fix failing test due to JDK bug.

The bug: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8169685

This came up when diagnosing a mind-numbingly perplexing failure on RawAttributeMapperTest from https://buildkite.com/bazel/google-bazel-presubmit/builds/17716#f428d533-71d6-4483-b138-5c21345b97f2, happening due to change https://bazel.googlesource.com/bazel/+/cbcffa054c50fd28e7c2fe5fe935d1991a322527 which has nothing to do with RawAttributeMapperTest at all.

The failure was triggered by removing LicensingTests.java. This changed how JUnit
scheduled analysis_select_test. This caused the ClassCastException checked in RawAttributeMapperTest#testGetAttribute,testVisitLabels to be compiled instead of interpreted. Due to https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8169685, this meant its stack trace was no longer available, so the tests couldn't check its error message.

I was able to produce a minimal repro by adding back in LicensingTests into the srcs of analysis_select_test, then ripping out all of LicensingTests except for testLicenseCheckingTakesOnlyOneSelectBranch.  When I commented out this line:

//  ConfiguredTarget eve = getConfiguredTarget("//eden:eve");

RawAttributeMapperTest failed. When I left it in, the test succeeded.

See https://github.com/bazelbuild/bazel/issues/7444.

PiperOrigin-RevId: 241937508
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index 8630b9a..851b187 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -75,8 +75,11 @@
     } catch (ClassCastException e) {
       // getIndexWithTypeCheck checks the type is right, but unexpected configurable attributes
       // can still trigger cast exceptions.
-      throw new IllegalArgumentException("wrong type for attribute \"" + attributeName + "\" in "
-          + ruleClass + " rule " + ruleLabel, e);
+      throw new IllegalArgumentException(
+          String.format(
+              "wrong type for attribute \"%s\" in %s rule %s: expected %s, is %s",
+              attributeName, ruleClass, ruleLabel, type, value.getClass().getSimpleName()),
+          e);
     }
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
index 2078904..f6cbbfb 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
@@ -66,9 +66,10 @@
       fail("Expected srcs lookup to fail since the returned type is a SelectorList and not a list");
     } catch (IllegalArgumentException e) {
       assertThat(e)
-          .hasCauseThat()
           .hasMessageThat()
-          .containsMatch(".*SelectorList cannot be cast to .*java\\.util\\.List");
+          .isEqualTo(
+              "wrong type for attribute \"srcs\" in sh_binary rule //x:myrule: "
+                  + "expected list(label), is SelectorList");
     }
   }
 
@@ -99,9 +100,10 @@
       fail("Expected label visitation to fail since one attribute is configurable");
     } catch (IllegalArgumentException e) {
       assertThat(e)
-          .hasCauseThat()
           .hasMessageThat()
-          .containsMatch(".*SelectorList cannot be cast to .*java\\.util\\.List");
+          .isEqualTo(
+              "wrong type for attribute \"srcs\" in sh_binary rule //x:myrule: "
+                  + "expected list(label), is SelectorList");
     }
   }