Skip to content

Commit

Permalink
Fix failing test due to JDK bug.
Browse files Browse the repository at this point in the history
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 #7444.

PiperOrigin-RevId: 241937508
  • Loading branch information
gregestren authored and copybara-github committed Apr 4, 2019
1 parent 4a69b1b commit d3c4073
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ public <T> T get(String attributeName, Type<T> type) {
} 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public void testGetAttribute() throws Exception {
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");
}
}

Expand Down Expand Up @@ -99,9 +100,10 @@ public void testVisitLabels() throws Exception {
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");
}
}

Expand Down

0 comments on commit d3c4073

Please sign in to comment.