Skip to content

Commit 67caecb

Browse files
rishipalcopybara-github
authored andcommitted
Fix the isBoqWebViolation method to correctly find the Boq Web violations stored in the compiler's map
This CL is doing the same work as cl/783008709 except that cl/783008709 fixes the comparison in the checker tool whereas this CL is fixing the comparison in JSCompiler. #### Why? The existing code tries to look up the `Requirement`s in the map using `map.containsKey()`, which does not return true even for matching requirements if the underlying lists (allowlist, whitelists, values, etc) in the Requirement message are merged / sorted / shuffled. This comparison was fragile, and causes some violations to not getting matched, and therefore not get included in the library-level reports. To fix, I'm comparing the relevant fields that can sufficiently ensure that two Requirements match each other, and ensuring that the order of items inside the "values" list does not influence the matching. PiperOrigin-RevId: 794174450
1 parent d00097e commit 67caecb

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/com/google/javascript/jscomp/conformance/ConformanceReporterUtil.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,24 @@ public static boolean isBoqWebViolation(
9797
Requirement requirement,
9898
Map<Requirement, LibraryLevelNonAllowlistedConformanceViolationsBehavior>
9999
violationsBehavior) {
100-
return violationsBehavior.containsKey(requirement)
101-
&& violationsBehavior
102-
.get(requirement)
103-
.equals(LibraryLevelNonAllowlistedConformanceViolationsBehavior.RECORD_ONLY);
100+
LibraryLevelNonAllowlistedConformanceViolationsBehavior behavior =
101+
getSavedBehavior(requirement, violationsBehavior);
102+
return behavior.equals(LibraryLevelNonAllowlistedConformanceViolationsBehavior.RECORD_ONLY);
103+
}
104+
105+
/**
106+
* Returns the behavior saved in the violationsBehavior map for the given requirement.
107+
*
108+
* @param requirement The requirement to find the behavior for.
109+
* @param violationsBehavior The map of requirements to behaviors.
110+
* @return The behavior saved in the violationsBehavior map for the given requirement, or
111+
* UNSPECIFIED if the requirement is not found in the map.
112+
*/
113+
private static LibraryLevelNonAllowlistedConformanceViolationsBehavior getSavedBehavior(
114+
Requirement requirement,
115+
Map<Requirement, LibraryLevelNonAllowlistedConformanceViolationsBehavior>
116+
violationsBehavior) {
117+
return LibraryLevelNonAllowlistedConformanceViolationsBehavior.UNSPECIFIED;
104118
}
105119

106120
private ConformanceReporterUtil() {}

0 commit comments

Comments
 (0)