Anonyme Klasse im super() Aufruf - VerifyError

S

Sebastian Millies

Hallo,

ich versuche, Coding für die lexikalische Analyse arithmetischer
Ausdrücke anzupassen, das ursprünglich von Axel T. Schreiner (Uni
Osnabrück) stammt. Beim Versuch der Ausführung bekomme ich:

java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method:
<init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
stack

Grund ist anscheinend der Versuch, eine anonyme Subklasse von FilterReader
als Argument des super()-Aufrufs zu verwenden. Wie kann ich (in Java 5)
erreichen, was ich will? Hier der Code:

/** lexical analyzer for arithmetic expressions.
Fixes the lookahead problem for TT_EOL.
*/
public class Scanner extends StreamTokenizer
{
/** kludge: pushes an anonymous Reader which inserts
a space after each newline.
*/
public Scanner( Reader r )
{
super( new FilterReader( new BufferedReader( r ) )
{
protected boolean addSpace; // kludge to add space after \n

public int read() throws IOException
{
int ch = addSpace ? ' ' : in.read();
addSpace = ch == '\n';
return ch;
}
});
}

public static void main( String[] args )
{
Scanner scanner = new Scanner( new StringReader("1+2") ); // !!!
}
}


Vielen Dank,
Sebastian
 
S

Sebastian Millies

Am Thu, 13 Jul 2006 12:22:27 +0200 schrieb Sebastian Millies:
Hallo,

ich versuche, Coding für die lexikalische Analyse arithmetischer
[...]

Sorry, wrong language. Here I go again:

I'm trying to re-use coding orginally by Axel T. Schreiner
(Univ. of Osnabrück) for the lexical analysis of arithmetic
expressions. When I try to run the main class, I get an error:

java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method:
<init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
stack

The reason seems to have to do with using an anonymous subclass of
FilterReader as an argument in the call to super(). How can I achieve
what I want to do (in Java 5) ? Here's the code:

/** lexical analyzer for arithmetic expressions.
Fixes the lookahead problem for TT_EOL.
*/
public class Scanner extends StreamTokenizer
{
/** kludge: pushes an anonymous Reader which inserts
a space after each newline.
*/
public Scanner( Reader r )
{
super( new FilterReader( new BufferedReader( r ) )
{
protected boolean addSpace; // kludge to add space after \n

public int read() throws IOException
{
int ch = addSpace ? ' ' : in.read();
addSpace = ch == '\n';
return ch;
}
});
}

public static void main( String[] args )
{
Scanner scanner = new Scanner( new StringReader("1+2") ); // !!!
}
}

Thanks,
Sebastian
 
I

Ingo R. Homann

Hi,

Sebastian said:
java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method:
<init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
stack

Sounds like a Runtime/JRE/Linker/Classpath/build-Error - nothing that
can be solved by your code. Have you tried re-compiling your project?

Ciao,
Ingo
 
C

Chris Uppal

Sebastian said:
The reason seems to have to do with using an anonymous subclass of
FilterReader as an argument in the call to super(). How can I achieve
what I want to do (in Java 5) ? Here's the code:

That code compiles and runs OK for me, using both jdk 1.5.0 and 1.4.2.

If recompiling doesn't fix it for your environment, then you could try removing
the (implicit) reference to 'this' in the super call. Something like:

/** lexical analyzer for arithmetic expressions.
Fixes the lookahead problem for TT_EOL.
*/
public class Scanner extends StreamTokenizer
{
/** kludge: pushes an anonymous Reader which inserts
a space after each newline.
*/
private static class Kludge
extends FilterReader
{
private boolean addSpace;

public Kludge(Reader reader)
{
super(reader);
}

public int read() throws IOException
{
int ch = addSpace ? ' ' : in.read();
addSpace = ch == '\n';
return ch;
}
} // end of Kludge

public Scanner( Reader r )
{
super( new Kludge( new BufferedReader( r ) ) )
}

Or there is no real reason not to make Kludge a top-level class (but not
public).

-- chris
 
S

Sebastian Millies

Am Thu, 13 Jul 2006 13:00:07 +0200 schrieb Ingo R. Homann:
Hi,



Sounds like a Runtime/JRE/Linker/Classpath/build-Error - nothing that
can be solved by your code. Have you tried re-compiling your project?

Ciao,
Ingo

I tried recompiling and running this with jdk 1.4.2_07, 1.5.0_07 and
1.6.0_beta2. The error occurs with Java SE 5 and 6, it does not
occur with Java 1.4.
-- Sebastian
 
S

Sebastian Millies

Am Thu, 13 Jul 2006 13:36:20 +0100 schrieb Chris Uppal:
That code compiles and runs OK for me, using both jdk 1.5.0 and 1.4.2.

If recompiling doesn't fix it for your environment, then you could try removing
the (implicit) reference to 'this' in the super call. Something like:

/** lexical analyzer for arithmetic expressions.
Fixes the lookahead problem for TT_EOL.
*/
public class Scanner extends StreamTokenizer
{
/** kludge: pushes an anonymous Reader which inserts
a space after each newline.
*/
private static class Kludge
extends FilterReader
{
private boolean addSpace;

public Kludge(Reader reader)
{
super(reader);
}

public int read() throws IOException
{
int ch = addSpace ? ' ' : in.read();
addSpace = ch == '\n';
return ch;
}
} // end of Kludge

public Scanner( Reader r )
{
super( new Kludge( new BufferedReader( r ) ) )
}

Or there is no real reason not to make Kludge a top-level class (but not
public).

-- chris

Thanks - using a static inner class or top-level class works in my
environment.

(BTW: I'm glad I don't have to wait for a fix from Oracle now.
My environment is the Oracle JDeveloper 10.1.3. It
seems to me that it is the way that the Oracle compiler
is at fault: the error does not occur
when the code is compiled from the command-line, it only
occurs when it is compiled from JDeveloper. Should have
checked that first).

Thanks again,
Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top