开发者

parseInt and parseLong throwing an UnsupportedOperationException

开发者 https://www.devze.com 2023-02-21 21:44 出处:网络
Integer.parseInt(\"5\") and Long.parseLong(\"5\") are throwing an UnsupportedOperationException in the Eclipse Expressions Window.

Integer.parseInt("5") and Long.parseLong("5") are throwing an UnsupportedOperationException in the Eclipse Expressions Window.

parseInt and parseLong throwing an UnsupportedOperationException

I think this is also the Exception I'm getting at runtime, but being new to Eclipse, I'm not sure how to find the type of e within a debug session:

public static long longTryParse(String text, long fallbackValue) {
  try {
    return Long.parseLong(text);
  } catch (Exception e) {
    return fallbackValue; // When stopping at a breakpoint here, Eclipse says that e is of type 'Exception'.  Well, that's informative.
  }
}

So ...

  1. Are these valid statements?
  2. If so, why am I getting an exce开发者_开发问答ption?
  3. (Of lesser importance) Why won't Eclipse say that e is of type UnsupportedOperationException rather than Exception during my debug session?

Thanks!


Are these valid statements?

Yes ... taken as Java expressions in the context of a normal Java program.

In the context of an Eclipse debugger's expression evaluator, I'm not sure.

If so, why am I getting an exception?

I don't know for sure, but I suspect that it is something to do with the debugger itself.

  • One possibility is that you are using the expression evaluation functionality incorrectly.

  • Another possibility is that this is a bug in the Eclipse debugger, or a mismatch between the Eclipse debugger and the debug agent in the JVM.

The one thing that I do know is that the parseInt and parseLong methods themselves don't throw UnsupportedOperationException. (In theory, they could because it is an unchecked exception. But I checked the source code for those 2 methods, and there's no way that the code could do that ... if executed in the normal way.)


The Google query - "site:eclipse.org +UnsupportedOperationException JDI" - shows a lot of hits in the Eclipse issues database and newsgroups / mailing lists.

In some cases, it looks like the problem is that the JDI / JNDI implementation for the target platform is incomplete. Could this be your problem? You mention you are doing Android development ...


According to java docs parseInt can throw only NumberFormatException,it means UnsupportedException comes from different place in your code.

parseInt

public static int parseInt(String s)
                    throws NumberFormatException

Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.


I do not think it is related to parseInt or parseLong. The exception clearly specifies "Exception processing async thread queue"

Older versions of Eclipse has been known to throw similar exceptions, when it is being used in Debug mode. But I think these were fixed in the newer version.

I know that your code is ok, because it would have thrown "NumberFormatException" if there was anything wrong.

I even tried an example just to make sure.

Long lVal = Long.parseLong("5");
System.out.println("lVal = " + lVal );

Output was

lVal = 5

With no exceptions


try to put sysout in catch block which shows the type of the exception.

System.out.println(e);

and moreover as suresh mention it can throw only NumberFormatException


I think you should first try to parse the text variable and put it in another long variable and print. So that you can know whether the parsing is done or not. So that you will know where the problem is.


Exception is the declared type of e and that is what is normally displayed in the tooltip in Java perspective. If eclipse doesn't tell you more, first make sure you are in debug perspective (not in Java perspective).

I guess you have a problem with the configuration of eclipse tooltips. You should see more information about the exception in the variable view (if it's not open, try Window/Show View/Variables).

Also, when debugging stops at your breakpoint, you can mark e in source and hit CTRL+I (inspect). You should get a popup telling you more about e.

EDIT: This is about finding out more about e. I agree with the earlier posters you cannot normally get an UnsupportedOperationException from your code. Seems like the problem is that debugging is not working correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消