Skip to content

Commit da0efeb

Browse files
committed
detect changes to /etc/hosts and warn user (processing#4738)
1 parent c6c433f commit da0efeb

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

java/src/processing/mode/java/runner/Runner.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.awt.Point;
3535
import java.io.*;
3636
import java.net.ConnectException;
37+
import java.net.InetAddress;
38+
import java.net.UnknownHostException;
3739
import java.util.*;
3840

3941
import com.sun.jdi.*;
@@ -82,6 +84,8 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException {
8284
// this.sketch = sketch;
8385
this.build = build;
8486

87+
checkLocalHost();
88+
8589
if (listener instanceof Editor) {
8690
this.editor = (Editor) listener;
8791
sketchErr = editor.getConsole().getErr();
@@ -116,6 +120,29 @@ public Runner(JavaBuild build, RunnerListener listener) throws SketchException {
116120
}
117121

118122

123+
/**
124+
* Has the user screwed up their hosts file?
125+
* https://github.com/processing/processing/issues/4738
126+
*/
127+
private void checkLocalHost() throws SketchException {
128+
try {
129+
InetAddress address = InetAddress.getByName("localhost");
130+
if (!address.getHostAddress().equals("127.0.0.1")) {
131+
System.err.println("Your computer is not properly mapping 'localhost' to '127.0.0.1',");
132+
System.err.println("which prevents sketches from working properly because 'localhost'");
133+
System.err.println("is needed to connect the PDE to your sketch while it's running.");
134+
System.err.println("If you don't recall making this change, or know how to fix it:");
135+
System.err.println("https://www.google.com/search?q=add+localhost+to+hosts+file+" + Platform.getName());
136+
throw new SketchException("Cannot run due to changes in your 'hosts' file. " +
137+
"See the console for details.", false);
138+
}
139+
140+
} catch (UnknownHostException e) {
141+
e.printStackTrace();
142+
}
143+
}
144+
145+
119146
public VirtualMachine launch(String[] args) {
120147
if (launchVirtualMachine(false, args)) {
121148
generateTrace();

todo.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
0256 (3.2.4 or 3.3)
22
X only require reference.zip (and internet connection) when building dist
33
X set text style properly for Contribution Manager error message
4+
X Detect changes to 'hosts' file in case users modify/remove localhost
5+
_ No sketch window opens after hitting Run if hosts file changed
6+
_ https://github.com/processing/processing/issues/4738
7+
_ https://github.com/processing/processing/issues/4735
8+
X https://github.com/processing/processing/issues/1868
9+
X https://github.com/processing/processing/issues/3123
410

511

612
_ Export Application fails on machines w/ non-ASCII chars in user name
@@ -20,10 +26,6 @@ _ https://github.com/processing/processing/commits/master/build/macosx/appbund
2026
_ https://github.com/processing/processing/commit/fa27b983e76fdbc5c4c1451a1f0d854c652b1639
2127
_ https://bitbucket.org/infinitekind/appbundler
2228

23-
_ Drew's freeze on startup
24-
_ No PDE window opens when started on MacOS X 10.11
25-
_ https://github.com/processing/processing/issues/4735
26-
2729
_ settings() present and pixelDensity() is in setup(), nothing set/no error
2830
_ https://github.com/processing/processing/issues/4703
2931

0 commit comments

Comments
 (0)