Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8114752

Null Pointer when using WebView with Twitter4j

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • web

      See http://forums.oracle.com/forums/thread.jspa?threadID=2247912&tstart=0 for full forum thread

      Using a WebView by itself is fine. Using a twitter4j instance by itself is also fine. But for some reason, when I use both, it bombs out with a null pointer and seems to be blaming a cookie!? But it seems if I put the twitter stuff first, it works. However, doing anything http related after the webView crashes it again with the same null pointer.

      The main issue arises when I get to the requestToken. You'll need twitter4j to test this:

      package webtest;
       
      import java.io.IOException;
      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.paint.Color;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;
      import twitter4j.Twitter;
      import twitter4j.TwitterException;
      import twitter4j.TwitterFactory;
      import twitter4j.auth.RequestToken;
       
      public class WebTest extends Application {
       
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              Application.launch(WebTest.class, args);
          }
          
          @Override
          public void start(Stage primaryStage) throws TwitterException, IOException {
              primaryStage.setTitle("Hello World");
              Group root = new Group();
              Scene scene = new Scene(root, 800, 600, Color.LIGHTGREEN);
       
              primaryStage.setScene(scene);
              primaryStage.setVisible(true);
              
              WebView browser = new WebView();
              browser.setPrefSize(600, 400);
              WebEngine webEngine = new WebEngine();
              webEngine.load("http://www.google.com");
              browser.setEngine(webEngine);
              root.getChildren().add(browser);
              
              Twitter twitter = new TwitterFactory().getInstance();
              twitter.setOAuthConsumer("Nothing", "Test");
              RequestToken requestToken = twitter.getOAuthRequestToken();
          }
      }


      Note: Using a valid "twitter.setOAuthConsumer("Nothing", "Test");" does the excat same thing, so it's not that I'm using an incorrect consumer key.

      Now, am I crazy, or is this really bombing out due to the combination of both? Commenting out the requestToken goes fine and commenting out the WebView stuff also goes fine....


      And here's the exception:

      Exception in Application start method
      java.lang.RuntimeException: java.lang.NullPointerException
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1137)
      at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2346)
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:388)
      at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:35)
      at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:168)
      at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
      at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:102)
      at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:121)
      at twitter4j.auth.OAuthAuthorization.getOAuthRequestToken(OAuthAuthorization.java:104)
      at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:271)
      at twitter4j.TwitterBaseImpl.getOAuthRequestToken(TwitterBaseImpl.java:264)
      at webtest.WebTest.start(WebTest.java:51)
      at com.sun.javafx.application.LauncherImpl$3.run(LauncherImpl.java:112)
      at com.sun.javafx.application.PlatformImpl$3.run(PlatformImpl.java:87)
      at com.sun.javafx.application.PlatformImpl$2.run(PlatformImpl.java:65)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$2.run(WinApplication.java:51)
      at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.NullPointerException
      at com.sun.webpane.webkit.network.CookieJar$PolicyDelegateFilter.shouldAccept(CookieJar.java:41)
      at com.sun.webpane.webkit.network.CookieManager.put(CookieManager.java:193)
      at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:710)
      at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
      ... 16 more
      BUILD SUCCESSFUL (total time: 3 seconds)

            vbaranov Vasiliy Baranov (Inactive)
            nlorain Nicolas Lorain (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: