Skip to content

Instantly share code, notes, and snippets.

@devinrsmith
Last active May 3, 2018 09:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrsmith/c2dddc652fbffe6404e9 to your computer and use it in GitHub Desktop.
Save devinrsmith/c2dddc652fbffe6404e9 to your computer and use it in GitHub Desktop.
UrlTest
javac -encoding UTF8 /pwd/UrlTest.java
java -cp /pwd UrlTest
rm /pwd/UrlTest.class
javac -encoding UTF8 /pwd/UrlTest.java
java -cp /pwd -Dfile.encoding=UTF8 UrlTest
rm /pwd/UrlTest.class
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
/**
* Created by dsmith on 4/8/15.
*/
public class UrlTest {
public static void main(String[] args) throws IOException {
final HttpURLConnection urlConnection = (HttpURLConnection)
URI.create("http://prod3.agileticketing.net/images/user/mfsf_3683/Tokyo-Fianceé-1.jpg").
toURL().
openConnection();
System.out.println(urlConnection.getResponseMessage());
}
}
@devinrsmith
Copy link
Author

I've run into this issue a couple times, where we'll pass around a pre-built jar and different environments act differently by default. As it stands now, the responsibility lies on me to always remember when using docker java to pass -Dfile.encoding=UTF8 (and it's probably good practice anyways). But again... whenever a bug like this pops up it takes me a couple hours to figure out what's going on and that's never fun. Should the docker java image have UTF8 by default?

$ docker run --rm -v $(pwd):/pwd java:8u40-jdk sh /pwd/run.sh
Not Found
$ docker run --rm -v $(pwd):/pwd java:8u40-jdk sh /pwd/runFix.sh
OK

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