dbconfession
dbconfession

Reputation: 1199

Java: Why aren't variable parameters updating as expected in Eclipse?

Based on my code below, When I debug and I get to the point in me(jurl instance), where con.setRequestMethod(method) is called, the Variables tab first shows:

Name            Value
-----------     ----------------------------------------        
this            jurl (id=128)
  -con          HttpsURLConnectionImpl (id=129)
    -method     "GET" (id=116)

method          "POST" (id=118)
furl            "https://www.someurl.com/login" (id=117)

If I'm to understand correctly then, shouldn't con.setRequestMethod("POST") change this.con.method (id 116) from "GET" to "POST"? Because it's not. As soon as debug passes con.setRequestMethod(method), this.con.method still says "GET". So either I'm missing something here, or Eclipse's variable tracker is bugged.

View.java

public Class View {
  private AccountManager accountManager = new AccountManager(this);

  private void login() {
    String username = textuser.getText();
    String password = textpass.getText();
    String locid = getLocId();
    Hashtable result = null;

    result = accountManager.login(username, password, locid);
  }  
}

AccountManager.java

public class AccountManager {
  public View Parent = null;
  private String USERNAME = null;
  private String PASSWORD = null;
  private String locid = null;

  public View Parent = null;

  public AccountManager(View view) {
    this.Parent=view;
    this._locationAssistant = l;
  }

  public Hashtable login(String username, String password, String locid) {
    final String USERNAME = username;
    final String PASSWORD = password;
    this.USERNAME = username;
    this.PASSWORD = password;
    Hashtable result = new Hashtable();

    URLVisitor vis = new URLVisitor();
    vis.setURL("https://www.someurl.com/login");
    vis.setMethod("POST");
    vis.execute();
  }
}

URLVisitor.java

public class URLVisitor {
  private String method= "GET";
  private String url;
  public jurl me = null;

  public URLVisitor() {
  }

  public void setURL(String url) {
    this.url = url;
  }

  public void setMethod(String method) {
    this.method = method;
  }

  public void execute() {
    me = new jurl(this.method, this.url);
  }
}

jurl.java

public class jurl {
  private URL url;
  private HttpURLConnection con = null;

  public jurl(String method, String furl) {
    try {
      url new URL(furl);
      con = (HttpURLConnection) url.openConnection();
      con.setRequestMethod(method);    
    }
  }
}

enter image description here

Upvotes: 0

Views: 312

Answers (2)

dbconfession
dbconfession

Reputation: 1199

I found it. When the original HttpURLConnection con, is created, con.method's default value is "GET". When con.setRequestMethod is called, however, for me, which is an instantiation that is created inside the already running vis instantiation, it's con.setRequestMethod("POST") is not reflected in vis.me.con.method, but instead one level down in vis.me.con.delegate.method.

Upvotes: 1

Stephen C
Stephen C

Reputation: 719336

As soon as debug passes con.setRequestMethod(method), this.con.method still says "GET".

You can't expect the field to change until after the setRequestMethod call returns. It sounds to me like the debugger is behaving normally / correctly.

It is also possible that I've misunderstood you, and that you are really seeing a stale value for that field. Try getting the debugger to refetch the value from the field.


But this should not affect the way that the code actually behaves, whether your are running it from the debugger or not.

Finally, note that your code doesn't actually call connect or attempt to look at the status or content, so it is academic what the state of the method field is. It won't be used ...

Upvotes: 0

Related Questions