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

WebView/WebEngine null pointer when also making HTTP send from other library

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • None
    • Windows XP SP3
      Version: 1.14.1 Source: NetBeans IDE 7.0 (Build 201104080000)
      Java jdk1.6.0_25
      JavaFX 2.0 Beta Plugin
      twitter4j-core-2.2.3.jar
      scribe-1.2.1.jar

    • web

      Hi Guys,

      let me start off with a disclaimer, I am not a pro at java, but have been playing with it for some years. Therefore I do not have the skills to dig deeper (or even know how to go about it).

      Now to the issue:
      I tried a very simple example which creates a WebView and then tries to connect to Twitter using twitter4j and then also separately using scribe-java. Both always end in the same null pointer, making me think that maybe the issue is with javafx and not with the two other libraries (possible incorrect assumption - but do not know where to go other than here). Hopefully you guys can either confirm or reject based on the following issue raised in the forums:

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

      The code in question is posted there and is quite basic. If any further details are required, I will be happy to provide them.

      A copy of the main issue is pasted below:

      -------------------------------------------------------SNIP-------------------------------------------------------
      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.AccessToken;
      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();
              browser.setEngine(webEngine);
       
              Twitter twitter = new TwitterFactory().getInstance();
              twitter.setOAuthConsumer("{myKey}", "{mySecret}");
      // Set break point here if you wish :)
              RequestToken requestToken = twitter.getOAuthRequestToken();
              if(requestToken.getAuthorizationURL()!=null){
                  webEngine.load(requestToken.getAuthorizationURL());
              }
              
              root.getChildren().add(browser);
              //AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,"1234567");
          }
      }
      -------------------------------------------------------SNIP-------------------------------------------------------


      And null pointer:
      -------------------------------------------------------SNIP-------------------------------------------------------
      run:
      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:48)
      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: 2 seconds)

      -------------------------------------------------------SNIP-------------------------------------------------------

      Thank you for your time. It would be great to gain a better understanding if I am doing something incorrect or silly!

            vbaranov Vasiliy Baranov (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: