Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reland "Audit hashCode overrides outside of packages/flutter"" #85567

Merged
merged 1 commit into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/bots/analyze.dart
Expand Up @@ -610,7 +610,7 @@ class Hash256 {
}

@override
int get hashCode => a ^ b ^ c ^ d;
int get hashCode => Object.hash(a, b, c, d);
}

// DO NOT ADD ANY ENTRIES TO THIS LIST.
Expand Down
15 changes: 1 addition & 14 deletions dev/devicelab/lib/framework/running_processes.dart
Expand Up @@ -28,20 +28,7 @@ class RunningProcessInfo {
}

@override
int get hashCode {
// TODO(dnfield): Replace this when Object.hashValues lands, https://github.com/dart-lang/sdk/issues/11617
int hash = 17;
if (pid != null) {
hash = hash * 23 + pid.hashCode;
}
if (commandLine != null) {
hash = hash * 23 + commandLine.hashCode;
}
if (creationDate != null) {
hash = hash * 23 + creationDate.hashCode;
}
return hash;
}
int get hashCode => Object.hash(pid, commandLine, creationDate);

@override
String toString() {
Expand Down
17 changes: 8 additions & 9 deletions dev/devicelab/test/adb_test.dart
Expand Up @@ -166,15 +166,14 @@ class CommandArgs {
}

@override
int get hashCode => 17 * (17 * command.hashCode + _hashArguments) + _hashEnvironment;

int get _hashArguments => arguments != null
? const ListEquality<String>().hash(arguments)
: null.hashCode;

int get _hashEnvironment => environment != null
? const MapEquality<String, String>().hash(environment)
: null.hashCode;
int get hashCode {
return Object.hash(
command,
Object.hashAll(arguments ?? const <String>[]),
Object.hashAllUnordered(environment?.keys ?? const <String>[]),
Object.hashAllUnordered(environment?.values ?? const <String>[]),
);
}
}

class FakeDevice extends AndroidDevice {
Expand Down
Expand Up @@ -183,8 +183,7 @@ class Rect {
final double bottom;

@override
int get hashCode =>
top.hashCode ^ left.hashCode ^ right.hashCode ^ bottom.hashCode;
int get hashCode => Object.hash(top, left, right, bottom);

@override
bool operator ==(Object other) {
Expand Down Expand Up @@ -216,7 +215,7 @@ class Size {
final double height;

@override
int get hashCode => width.hashCode ^ height.hashCode;
int get hashCode => Object.hash(width, height);

@override
bool operator ==(Object other) {
Expand Down
4 changes: 1 addition & 3 deletions dev/tools/localization/localizations_utils.dart
Expand Up @@ -128,9 +128,7 @@ class LocaleInfo implements Comparable<LocaleInfo> {
}

@override
int get hashCode {
return originalString.hashCode;
}
int get hashCode => originalString.hashCode;

@override
String toString() {
Expand Down
6 changes: 3 additions & 3 deletions dev/tools/vitool/lib/vitool.dart
Expand Up @@ -274,7 +274,7 @@ class FrameData {
}

@override
int get hashCode => size.hashCode ^ paths.hashCode;
int get hashCode => Object.hash(size, Object.hashAll(paths));

@override
String toString() {
Expand Down Expand Up @@ -328,7 +328,7 @@ class SvgPath {
}

@override
int get hashCode => id.hashCode ^ commands.hashCode ^ opacity.hashCode;
int get hashCode => Object.hash(id, Object.hashAll(commands), opacity);

@override
String toString() {
Expand Down Expand Up @@ -377,7 +377,7 @@ class SvgPathCommand {
}

@override
int get hashCode => type.hashCode ^ points.hashCode;
int get hashCode => Object.hash(type, Object.hashAll(points));

@override
String toString() {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/about.dart
Expand Up @@ -798,7 +798,7 @@ class _DetailArguments {
}

@override
int get hashCode => packageName.hashCode; // Good enough.
int get hashCode => hashValues(packageName, hashList(licenseEntries));
}

class _PackageLicensePage extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_driver/lib/src/driver/driver.dart
Expand Up @@ -814,5 +814,5 @@ class DriverOffset {
}

@override
int get hashCode => dx.hashCode ^ dy.hashCode;
int get hashCode => Object.hash(dx, dy);
}
6 changes: 1 addition & 5 deletions packages/flutter_tools/lib/src/asset.dart
Expand Up @@ -911,11 +911,7 @@ class _Asset {
}

@override
int get hashCode {
return baseDir.hashCode
^ relativeUri.hashCode
^ entryUri.hashCode;
}
int get hashCode => Object.hash(baseDir, relativeUri, entryUri.hashCode);
}

// Given an assets directory like this:
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter_tools/lib/src/base/fingerprint.dart
Expand Up @@ -128,10 +128,7 @@ class Fingerprint {
}

@override
// Ignore map entries here to avoid becoming inconsistent with equals
// due to differences in map entry order. This is a really bad hash
// function and should eventually be deprecated and removed.
int get hashCode => _checksums.length.hashCode;
int get hashCode => Object.hash(Object.hashAllUnordered(_checksums.keys), Object.hashAllUnordered(_checksums.values));

@override
String toString() => '{checksums: $_checksums}';
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/base/version.dart
Expand Up @@ -98,7 +98,7 @@ class Version implements Comparable<Version> {
}

@override
int get hashCode => major ^ minor ^ patch;
int get hashCode => Object.hash(major, minor, patch);

bool operator <(Version other) => compareTo(other) < 0;
bool operator >(Version other) => compareTo(other) > 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/doctor_validator.dart
Expand Up @@ -278,7 +278,7 @@ class ValidationMessage {
}

@override
int get hashCode => type.hashCode ^ message.hashCode ^ contextUrl.hashCode;
int get hashCode => Object.hash(type, message, contextUrl);
}

class NoIdeValidator extends DoctorValidator {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/ios/xcodeproj.dart
Expand Up @@ -302,7 +302,7 @@ class XcodeProjectBuildContext {
final EnvironmentType environmentType;

@override
int get hashCode => scheme.hashCode ^ configuration.hashCode ^ environmentType.hashCode;
int get hashCode => Object.hash(scheme, configuration, environmentType);

@override
bool operator ==(Object other) {
Expand Down
Expand Up @@ -129,9 +129,7 @@ class LocaleInfo implements Comparable<LocaleInfo> {
}

@override
int get hashCode {
return originalString.hashCode;
}
int get hashCode => originalString.hashCode;

@override
String toString() {
Expand Down
Expand Up @@ -326,12 +326,7 @@ class CustomDimensions {
}

@override
int get hashCode =>
toMap()
.values
.where((String element) => element != null)
.fold(Object().hashCode,
(int value, String element) => value ^ element.hashCode);
int get hashCode => Object.hashAll(toMap().values);
}

/// List of all fields used in CustomDimensions.
Expand Down
13 changes: 3 additions & 10 deletions packages/flutter_tools/lib/src/reporting/usage.dart
Expand Up @@ -486,7 +486,7 @@ class TestUsageCommand {
}

@override
int get hashCode => command.hashCode ^ parameters.hashCode;
int get hashCode => Object.hash(command, parameters);

@override
String toString() => 'TestUsageCommand($command, parameters:$parameters)';
Expand Down Expand Up @@ -514,11 +514,7 @@ class TestUsageEvent {
}

@override
int get hashCode => category.hashCode ^
parameter.hashCode ^
label.hashCode ^
value.hashCode ^
parameters.hashCode;
int get hashCode => Object.hash(category, parameter, label, value, parameters);

@override
String toString() => 'TestUsageEvent($category, $parameter, label:$label, value:$value, parameters:$parameters)';
Expand All @@ -544,10 +540,7 @@ class TestTimingEvent {
}

@override
int get hashCode => category.hashCode ^
variableName.hashCode ^
duration.hashCode ^
label.hashCode;
int get hashCode => Object.hash(category, variableName, duration, label);

@override
String toString() => 'TestTimingEvent($category, $variableName, $duration, label:$label)';
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/vscode/vscode.dart
Expand Up @@ -326,5 +326,5 @@ class VsCodeInstallLocation {

@override
// Lowest bit is for isInsiders boolean.
int get hashCode => installPath.hashCode ^ extensionsFolder.hashCode ^ edition.hashCode;
int get hashCode => Object.hash(installPath, extensionsFolder, edition);
}
Expand Up @@ -219,7 +219,7 @@ class CleanWorkspaceCall {
verbose == other.verbose;

@override
int get hashCode => workspacePath.hashCode;
int get hashCode => Object.hash(workspacePath, scheme, verbose);

@override
String toString() => '{$workspacePath, $scheme, $verbose}';
Expand Down