zrevai / ps3mediaserver

Automatically exported from code.google.com/p/ps3mediaserver
2 stars 0 forks source link

[Network] NPE on startup. #172

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Null pointer exception on startup.

What version of the product are you using? On what operating system?
SVN revison 198, 
URL: http://ps3mediaserver.googlecode.com/svn/trunk/ps3mediaserver
Windows Vista SP1
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

Please provide any additional information below and PLEASE JOIN debug.log 
file !!
java.lang.NullPointerException
    at net.pms.newgui.NetworkTab.build(NetworkTab.java:208)
    at net.pms.newgui.LooksFrame.buildMain(LooksFrame.java:266)
    at net.pms.newgui.LooksFrame.buildContent(LooksFrame.java:246)
    at net.pms.newgui.LooksFrame.<init>(LooksFrame.java:180)
    at net.pms.PMS.init(PMS.java:282)
    at net.pms.PMS.get(PMS.java:865)
    at net.pms.PMS.main(PMS.java:923)

---
            while (enm.hasMoreElements()) {
                NetworkInterface ni = enm.nextElement();
                names.add(ni.getName());
                interfaces.add(ni.getDisplayName().trim());
            }

---
Problem is:
String NetworkInterface.getDisplayName()
can return null if there is no network interface with the specified name.

Soluton: check return value and use getName instead.
--- suggested path ---
Index: net/pms/newgui/NetworkTab.java
===================================================================
--- net/pms/newgui/NetworkTab.java  (revision 198)
+++ net/pms/newgui/NetworkTab.java  (working copy)
@@ -205,7 +205,10 @@
            while (enm.hasMoreElements()) {
                NetworkInterface ni = enm.nextElement();
                names.add(ni.getName());
-               interfaces.add(ni.getDisplayName().trim());
+               String displayName = ni.getDisplayName();
+               if ( displayName == null )
+                 displayName = ni.getName();
+               interfaces.add(displayName.trim());
            }
        } catch (SocketException e1) {
            PMS.error(null, e1);

---

Original issue reported on code.google.com by A.Neshe...@gmail.com on 15 Jan 2009 at 8:26

GoogleCodeExporter commented 9 years ago
wow thank you ! I totally forgot that null value possibility... already fixed 
similar 
one in the HTTPServer class (I'm also changing it , that shouldn't prevent the 
network interface to be scanned)
wish every issues were like yours :)

Original comment by ps3mediaserver@gmail.com on 15 Jan 2009 at 8:45

GoogleCodeExporter commented 9 years ago
Maybe you should totaly ignore such interfaces, my system have a lot interfaces 
without any ip addreses attached. Additional check is needed.
I suggest you to list interfaces with ip addresses, this should discard all 
unusable 
interfaces.
--
while (enm.hasMoreElements()) 
{
  NetworkInterface ni = enm.nextElement();
  // check for interface has at leat one ip address.
  if ( ni.getInetAddresses().hasMoreElements() )
  {
    names.add(ni.getName());
    String displayName = ni.getDisplayName();
    if ( displayName == null )
      displayName = ni.getName();
    interfaces.add(displayName.trim());
  }
}
--

Original comment by A.Neshe...@gmail.com on 15 Jan 2009 at 9:32

GoogleCodeExporter commented 9 years ago
thanks

Original comment by ps3mediaserver@gmail.com on 16 Jan 2009 at 12:18