jmx-dev JDK-8031753: JMXServiceURL should not use getLocalHost or its usage should be enhanced

Maryan Bagnyuk (aka Maryan Bahnyuk) marbuga at gmail.com
Tue Feb 4 11:20:47 PST 2014


Hello.

Do I understand correctly that my conclusions regarding "fixing the 
hostname is not an option" are incorrect?

Or may/should it be fixed in the following way:

              try {
- local = InetAddress.getLocalHost();
+ local = InetAddress.getByName("localhost");
              } catch (UnknownHostException e) {

Sincerely, Maryan

P.S. Sorry if my previous message was impolite or jokes were too plain

On 01/28/2014 02:50 AM, Rob McKenna wrote:
> Hi Maryan,
>
> I'm cc'ing the jmx-dev folks. (and bcc'ing the jdk7u-dev alias) 
> Hopefully they'll help move this conversation forward.
>
>     -Rob
>
> On 27/01/14 20:42, Maryan Bagnyuk (aka Maryan Bahnyuk) wrote:
>> Hello
>>
>> As a reporter of JI-9009639 / JDK-8031753 
>> <https://bugs.openjdk.java.net/browse/JDK-8031753> bug I'd like to 
>> inform you about the following.
>>
>>
>> Jaroslav Bachorík 
>> <https://bugs.openjdk.java.net/secure/ViewProfile.jspa?name=jbachorik>added 
>> a comment -2014-01-22 04:32
>> Not a regression.
>>
>> Oops. Sorry. Indeed I should have left this field blank.
>> I'd understood the meaning of 'Regression' field incorrectly and had 
>> filled it in bug report by mistake. :(
>>
>>
>> Jaroslav Bachorík 
>> <https://bugs.openjdk.java.net/secure/ViewProfile.jspa?name=jbachorik>added 
>> a comment -2014-01-22 04:32
>> If you insist on this issue being a regression, please, provide the 
>> exact version where the behavior was as expected.
>>
>> As I see all branches have this code for ages...
>>
>> [marbug at server1 jdk]$ pwd && hg annotate -f -a -u -d -n -c 
>> ./src/share/classes/javax/management/remote/JMXServiceURL.java | grep 
>> 'local = InetAddress.getLocalHost();'
>> /home/marbug/cpp/jab/tmp/jdk6/jdk
>>     ohair   9 2d585507a41b Fri Jan 30 16:27:33 2009 -0800 
>> src/share/classes/javax/management/remote/JMXServiceURL.java: local = 
>> InetAddress.getLocalHost();
>> [marbug at server1 jdk]$ pwd && hg annotate -r 0 -f -a -u -d -n -c 
>> ./src/share/classes/javax/management/remote/JMXServiceURL.java | grep 
>> 'local = InetAddress.getLocalHost();'
>> /home/marbug/cpp/jab/tmp/jdk6/jdk
>> duke 0 0c738a3e5791 Fri Jan 30 16:00:53 2009 -0800 
>> src/share/classes/javax/management/remote/JMXServiceURL.java: local = 
>> InetAddress.getLocalHost();
>> [marbug at server1 jdk]$ cd ../../jdk7u/jdk/
>> [marbug at server1 jdk]$ pwd && hg annotate -f -a -u -d -n -c 
>> ./src/share/classes/javax/management/remote/JMXServiceURL.java | grep 
>> 'local = InetAddress.getLocalHost();'
>> /home/marbug/cpp/jab/tmp/jdk7u/jdk
>>      duke    0 37a05a11f281 Sat Dec 01 00:00:00 2007 +0000 
>> src/share/classes/javax/management/remote/JMXServiceURL.java: local = 
>> InetAddress.getLocalHost();
>> [marbug at server1 jdk]$ cd ../../jdk8/jdk/
>> [marbug at server1 jdk]$ pwd && hg annotate -f -a -u -d -n -c 
>> ./src/share/classes/javax/management/remote/JMXServiceURL.java | grep 
>> 'local = InetAddress.getLocalHost();'
>> /home/marbug/cpp/jab/tmp/jdk8/jdk
>>      duke    0 37a05a11f281 Sat Dec 01 00:00:00 2007 +0000 
>> src/share/classes/javax/management/remote/JMXServiceURL.java: local = 
>> InetAddress.getLocalHost();
>> [marbug at server1 jdk]$ cd ../../jdk9/jdk/
>> [marbug at server1 jdk]$ pwd && hg annotate -f -a -u -d -n -c 
>> ./src/share/classes/javax/management/remote/JMXServiceURL.java | grep 
>> 'local = InetAddress.getLocalHost();'
>> /home/marbug/cpp/jab/tmp/jdk9/jdk
>>      duke    0 37a05a11f281 Sat Dec 01 00:00:00 2007 +0000 
>> src/share/classes/javax/management/remote/JMXServiceURL.java: local = 
>> InetAddress.getLocalHost();
>>
>> So the expected behaviour is just my conslusion/suggestion.
>>
>>
>> Jaroslav Bachorík 
>> <https://bugs.openjdk.java.net/secure/ViewProfile.jspa?name=jbachorik>added 
>> a comment -2014-01-22 04:32
>> I would argue that workaround should be L - it is easy to fix the 
>> hostname and the solution is persistent. If the reporter can describe 
>> a situation where fixing the hostname is not an option the workaround 
>> should stay at M.
>>
>> As I understand you suggest to fix hostname and/or an appropriate 
>> record in /etc/hosts (under Linux).
>> Everyone suggest this in 'google search'... :( But IMHO it's not an 
>> option because:
>>
>> 1) As far as I know no one must have root access to run programs with 
>> JMX agent.
>> 1.1) With this suggestion everyone must have root access (because 
>> only root or sudo-ed user may change hostname and/or /etc/hosts)
>> 1.1.1) What if someone do not have root access to his PC (some 
>> companies do not allow to install additional software without their 
>> permissions)?
>> 1.1.2) Will you add the appropriate note to the 'Install' section in 
>> Java manual/documentation? Or should everyone just google this 
>> exception to find the fix of this issue? :)
>>
>> 2) Indeed Agent does not use hostname or it's IP to run JMX server 
>> (please take a look at my original post)
>> 2.1) If Agent does not use it (i.e. hostname/IP) then why should it 
>> depend on it?
>>
>> 3) Why should I change hostname if other services work correctly 
>> without it?
>> 3.1) OS ignores that hostname can't be resolved to some IP and is 
>> started successfully
>> 3.2) Apache does so too (because it listens on 0.0.0.0 in IPv4)
>> 3.3) SSH server as well ...
>> 3.4) etc., etc., etc.
>> 3.5) but java throws an exception
>> IMHO this does not follow the 'general' scheme ;)
>>
>> 4) How about JMX client (i.e. "Connecting to the JMX Agent 
>> Programmatically ")?
>> http://docs.oracle.com/javase/7/docs/technotes/guides/management/agent.html#gdevg 
>>
>> STR:
>> 4.1) server1 is behind NAT (example 1: on my VM, example 2: in Amazon 
>> Cloud)
>> 4.2) port mapping is configured from external IP to the local one 
>> (i.e. there is only local network IP on interface)
>> 4.3) I have associated my hostname (for instance, 
>> server1.customer22.example.com) with 127.0.0.1 ( Is it a good idea to 
>> do this in Amazon Cloud? IMHO no. ;) )
>> 4.4) I start a program (Cassandra, Program4STR, etc.) via Agent
>> 4.5) if someone will change a record for 
>> server1.customer22.example.com to the correct external IP then why 
>> should agent connect to external IP instead of local one? :)
>> 4.5.1) if I run client on server1 then it's enough to connect to 
>> localhost instead of external IP. Isn't it?
>> 4.5.2) if I start client on another PC then in any case I'll pass the 
>> needed value in 'host' parameter to JMXServiceURL(...)
>>
>> 5) etc., etc., etc. (see examples from my original post and imagine 
>> how client will connect to JMX server in each case)
>>
>>
>> Indeed the decision is 'up to you' but IMHO making the suggested 
>> change will simplify everything, save time of many people (they will 
>> not need to change hostname and/or /etc/hosts), google will deprecate 
>> search of ' Error: Exception thrown by the agent : 
>> java.net.MalformedURLException: Local host name unknown:' string and 
>> at least several developers and system administrators will be happy 
>> not to take care about hostname ... At least for Java and programs 
>> which use Agent ;)
>>
>>
>> Thanks
>>
>


-- 
Sincerely,
Maryan Bagnyuk (aka Maryan Bahnyuk)

marbuga at gmail.com
marbug at mail.ru
marbug at meta.ua

Cell phone (MTS): 066-498-99-24
Cell phone (Kyivstar): 067-131-27-37

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/jmx-dev/attachments/20140204/c187b647/attachment-0001.html 


More information about the jmx-dev mailing list