Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 1a9ffaa

Browse files
committed
SI-9206 BooleanProp if set and not untrue
Previously, handy `sys.BooleanProp.keyExists` ignored the property value. While trying not to make any real estate puns, this commit will let it go false if a value is supplied that is not true in the usual Java sense. But what is truth? Allows `scala -Dscala.color=off`, for example.
1 parent 305dd96 commit 1a9ffaa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/library/scala/sys/BooleanProp.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ object BooleanProp {
6363
def valueIsTrue[T](key: String): BooleanProp = new BooleanPropImpl(key, _.toLowerCase == "true")
6464

6565
/** As an alternative, this method creates a BooleanProp which is true
66-
* if the key exists in the map. This way -Dfoo.bar is enough to be
67-
* considered true.
66+
* if the key exists in the map and is not assigned a value other than "true",
67+
* compared case-insensitively, or the empty string. This way -Dmy.property
68+
* results in a true-valued property, but -Dmy.property=false does not.
6869
*
6970
* @return A BooleanProp with a liberal truth policy
7071
*/
71-
def keyExists[T](key: String): BooleanProp = new BooleanPropImpl(key, _ => true)
72+
def keyExists[T](key: String): BooleanProp = new BooleanPropImpl(key, s => s == "" || s.equalsIgnoreCase("true"))
7273

7374
/** A constant true or false property which ignores all method calls.
7475
*/

0 commit comments

Comments
 (0)