jitsi/ice4j

Method mismatch when expecting a true or false result

mondain opened this issue · 8 comments

Since Boolean.getBoolean(str) will always return false in this code block if(!Boolean.getBoolean(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE)), I believe it is in error and that this is actually what was intended if(!StackProperties.getBoolean(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE, false))

This is the only way to get true via Boolean.getBoolean("true").

if(!Boolean.getBoolean(StackProperties.KEEP_CRANS_AFTER_A_RESPONSE))

Since Boolean.getBoolean(str) will always return false in this code block

I don't understand why it would always return false. From the documentation of Boolean.getBoolean(String):

Returns true if and only if the system property named by the argument exists and is equal to the string "true".

Because you're not checking a system property by that key, you're checking the key itself ala
Boolean.getBoolean("org.ice4j.KEEP_CRANS_AFTER_A_RESPONSE")

As documented, the argument passed to Boolean.getBoolean() names a system property which will be checked, which is exactly what we provide:
https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#getBoolean(java.lang.String)

You might want to take a closer look @bgrozev before discounting what I'm informing you about. You are not passing a property as I've shown, you are passing a string that will never equal "true" nor "false", it will in fact always be equal to "org.ice4j.KEEP_CRANS_AFTER_A_RESPONSE" which Boolean.getBoolean will respond with false since it doesn't equal true. What am I failing to get across here?

This is precisely why someone on the Jitsi team created the StackProperties.getBoolean() method, which does what you think it would.

@bgrozev after closer examination, I confused this with Boolean.valueOf(), you are in-fact correct; Boolean.getBoolean(key) does a call to System.getProperty(key); my mistake.

You might want to take a closer look @bgrozev before discounting what I'm informing you about.

I am not discounting what you wrote and I did take a closer look. In fact, I went as far as running a test program just in case I missed something:

import java.util.*;
import java.net.*;


public class Test
{
  public static void main(String[] argv)
  throws Exception
  {

   System.err.println(Boolean.getBoolean("org.ice4j.PROP"));
  }
}

The result is this:

$ java  -Dorg.ice4j.PROP=true Test
true
$ java  -Dorg.ice4j.PROP=false Test
false

What am I failing to get across here?

You are failing to read the documentation that I first quoted and then linked to.

Thanks for your time, see my comment.