3
static final boolean $assertionsDisabled = !java/util/TaskQueue.desiredAssertionStatus();

which was seen in the source file java.util.TaskQueue.java

albusshin
  • 3,930
  • 3
  • 29
  • 57
HeJian
  • 98
  • 6
  • 2
    So what's the question? It's a boolean variable set to the inverted return value of the `desiredAssertionStatus()` method. Apprently, the `java/util/TaskQueue` part is no valid Java source code. – Thomas May 23 '12 at 09:22

3 Answers3

11

Quoting 6.2.1 Assertion Overhead:

It is useful to understand how the assertion mechanism works to see how assertion statements can affect performance. When the compiler finds an assertion in a class, it adds a generated static final field named $assertionsDisabled to the class. The field is left unassigned (this is legal bytecode). The assertion itself is compiled into a statement of the form:

if ($assertionsDisabled)
  if (!boolean_expression)
    throw new AssertionError(String_expression);
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Thanks, @Tomasz Nurkiewicz. Perfect answer (+1). But I believe that this is not what HeJian asked. I believe he just did not understand what does this line syntactically mean. – AlexR May 23 '12 at 09:35
3

Since java identifiers can contain Latin letters, $, _ and digits starting from letter where $ and _ are kind of letters $assertionsDisabled is a valid java identifiers of type boolean.

java/util/TaskQueue.desiredAssertionStatus() does not seem like a valid expression. Probably it should look like java.util.TaskQueue.desiredAssertionStatus(). In this case it is invocation of static method desiredAssertionStatus() from class TaskQueue.

This method returns boolean result. The ! reverses the result.

The only question is what is it really? Since the obvious syntax mistake appears here (/ instead of .) I assume that this line is a result of decompilation of java code or "bad" coding attempt. Am I right?

I have just checked source code of java.util.TaskQueue.java. It does not contain such line. So, I am pretty sure now that you got it from de-compilation. Do you probably have IDE plug-in that decompiles all classes if their source code is not found?

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • @HeJian, connect JDK sources to your JDK. The JDK source is located under your JDK installation directory in file `src.zip` – AlexR May 23 '12 at 09:37
1

It is because this class has an assertion, then the compiler creates this variable for itself.

Paulo
  • 11
  • 1