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

scala.sys.env should be case-insensitive on Windows #9957

Closed
scabug opened this issue Oct 11, 2016 · 12 comments · Fixed by scala/scala#8579
Closed

scala.sys.env should be case-insensitive on Windows #9957

scabug opened this issue Oct 11, 2016 · 12 comments · Fixed by scala/scala#8579
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 11, 2016

java.lang.System.getenv is case-insensitive on Windows. Shall we follow its behavior?

@scabug
Copy link
Author

scabug commented Oct 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9957?orig=1
Reporter: @Atry
Affected Versions: 2.10.6, 2.11.8, 2.12.0-RC1

@scabug
Copy link
Author

scabug commented Oct 11, 2016

@som-snytt said:
I didn't try, but Javadoc says "The returned map is typically case-sensitive on all platforms."

@scabug
Copy link
Author

scabug commented Oct 11, 2016

@Atry said:
I mean java.lang.System.getenv(String)

@SethTisue
Copy link
Member

currently env returns a Map. in order to make it case-insensitive, we'd have to add new API. in 2.13, scala.sys will become its own module, at which point this could be addressed if someone cares to.

closing since scala.sys issues will no longer be tracked here in scala/bug. I've made a "module:scala.sys" label so we can find relevant issues once the module has its own repo

@SethTisue SethTisue reopened this Nov 21, 2018
@stefanobaghino
Copy link

stefanobaghino commented Oct 17, 2019

@SethTisue Is this still the relevant place to talk about this? I've noticed the issue today by chance and I was thinking to use System.getenv(String) (which behaves correctly on Windows), doing something along these lines, so to not have to add a new API or introduce a breaking change (signature-wise, at least, I hope no one is relying on this behavior, which I believe can be anyhow considered incorrect):

  private final class Env extends immutable.Map[String, String] {

    override def +[V1 >: String](kv: (String, V1)): Map[String, V1] =
      iterator.toMap + kv

    override def get(key: String): Option[String] =
      Option(System.getenv(key))

    override def iterator: Iterator[(String, String)] =
      JavaConverters.mapAsScalaMap(System.getenv()).iterator

    override def -(key: String): Map[String, String] =
      iterator.toMap - key

  }

  /** An immutable Map representing the current system environment.
   *
   *  @return   a Map containing the system environment variables.
   */
  def env: immutable.Map[String, String] = new Env

I noticed that env is currently a def, so it may be desirable to turn Env in a final class and env back to a def, but the reason behind it is unclear to me (maybe something related to the behavior of the Java runtime but I'm not sure).

@stefanobaghino
Copy link

If this is not the right place to discuss about this I'd be very happy to move the discussion somewhere else. 😉

@som-snytt
Copy link

There is a code comment suggesting they want to remove the related SystemProperties map in favor of a simple forwarder to getProperty.

I'd expect the same thinking to apply here, with the additional prejudice that the semantics for case-sensitivity are strange.

An updated map would lose its special get.

Interacting with process environment is via processBuilder.environment in java and scala.sys.process just lets you supply extra env mappings.

The proposed solution does have the virtue of not changing the API.

@Atry
Copy link

Atry commented Oct 28, 2019

Shall we just add a withDefault to the original map?
scala/scala#8508

@som-snytt
Copy link

I couldn't think of how it wouldn't be weird asymmetry, "get didn't return my "shell"." "You have to use apply." "Oh, yeah."

@Atry
Copy link

Atry commented Oct 28, 2019

Your argument applies to all usage of withDefault.

@Atry
Copy link

Atry commented Oct 28, 2019

I couldn't think of how it wouldn't be weird asymmetry, "get didn't return my "shell"." "You have to use apply." "Oh, yeah."

It's exact the same behavior as Java System.getenv().get("path") vs System.getenv("path").

@SethTisue SethTisue added this to the Backlog milestone Dec 5, 2019
@som-snytt
Copy link

I agree with the previous comments, that conventionally you'd use apply for the special "platform-specific" behavior. I'm too lazy to exercise the behavior, as I am lying in bed with my Mac and not sitting out in the other room with the test bed windoze box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants