-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
[flutter_tools] Version.unknown
is equivalent to Version(0,0,0)
under compareTo
, which can result in surprising behavior
#124756
Labels
c: tech-debt
Technical debt, code quality, testing, etc.
tool
Affects the "flutter" command-line tool. See also t: labels.
Comments
andrewkolos
added
tool
Affects the "flutter" command-line tool. See also t: labels.
c: tech-debt
Technical debt, code quality, testing, etc.
labels
Apr 13, 2023
andrewkolos
changed the title
[flutter_tools]
[flutter_tools] Apr 13, 2023
Version.unknown
is equivalent to Version(0,0,0) under compareTo
which can result in surprising behavior Version.unknown
is equivalent to Version(0,0,0)
under compareTo
, which can result in surprising behavior
Perhaps it should work more like a nan! 😅 |
8 tasks
auto-submit bot
pushed a commit
that referenced
this issue
Apr 15, 2023
Fixes #124756 by removing the concept of `Version.unknown`. `Version` fields that needed the ability to represent an unknown version have been made nullable. Assigning `null` to them represents an unknown version.
exaby73
pushed a commit
to NevercodeHQ/flutter
that referenced
this issue
Apr 17, 2023
Fixes flutter#124756 by removing the concept of `Version.unknown`. `Version` fields that needed the ability to represent an unknown version have been made nullable. Assigning `null` to them represents an unknown version.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
gmackall
pushed a commit
to gmackall/flutter
that referenced
this issue
May 4, 2023
Fixes flutter#124756 by removing the concept of `Version.unknown`. `Version` fields that needed the ability to represent an unknown version have been made nullable. Assigning `null` to them represents an unknown version.
gmackall
pushed a commit
to gmackall/flutter
that referenced
this issue
May 5, 2023
Fixes flutter#124756 by removing the concept of `Version.unknown`. `Version` fields that needed the ability to represent an unknown version have been made nullable. Assigning `null` to them represents an unknown version.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
c: tech-debt
Technical debt, code quality, testing, etc.
tool
Affects the "flutter" command-line tool. See also t: labels.
Directly related to #121468.
Filing this as a sub-issue to be fixed with its own PR (this also affects non Android Studio-related code).
Context
Version
is a class that is used to represent a version of multiple pieces of software used throughout the tool, including Android Studio, IntelliJ, Visual Studio Code, and Cocoapods.Issue
Version
has a null-object1 instantiation,Version.unknown
, which is used in a few places to represent the flutter tool being unable to detect the version of some software. BecauseVersion
also implementsComparable
, it is easy to write logic that compares a more typical version object (e.g.Version(1, 2, 3)
) toVersion.unknown
, which doesn't semantically make sense. For a specific example, considerVersion(0,0,0) == Version.unknown
, which resolves totrue
.Because of this, branching logic based on Version comparison is prone to error if
Version.unknown
is used. If someone usesVersion.unknown
and they compare Verison objects, they must remember to explicitly check forVersion.unknown
in addition to those comparisons. Otherwise, they are at risk of treatingVersion.unknown
as a legitimate version (0.0.0). Again, see #121468.Possible fixes
Version.unknown
entirely. The drawback is that tool code has to use something else to represent the inability to find/detect a version within a software installation.null
is the easiest choice, but the meaning ofnull
is not as clear asVersion.unknown
, and it results in slightly less readable code.compareTo
function ofVersion
aware ofVersion.unknown
(which should be made into astatic const
). Specifically, comparison withVersion.undefined
should result in an exception being thrown. While arguably better than the current behavior, users still need to remember to check forVersion.unknown
before making comparisons.I suggest option 1.
Footnotes
I'm abusing terminology here, since this object doesn't have any null/default behavior, but it still accomplishes something a null-object is typically used to do—avoiding references to
null
. ↩The text was updated successfully, but these errors were encountered: