From: Matthew Khouzam Date: Wed, 27 Nov 2013 19:34:28 +0000 (-0500) Subject: ctf: Catch ANTLR runtime exceptions in Metadata parsing X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=4b825d8bb8b841f6b48ff43fec30c6b140bd4196;p=deliverable%2Ftracecompass.git ctf: Catch ANTLR runtime exceptions in Metadata parsing Change-Id: Ia50ee58b56a6e50b213e008950322c2e04231c28 Signed-off-by: Matthew Khouzam Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/19000 --- diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java index 7c9eed01c6..8fe1f602e4 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -28,9 +28,9 @@ import java.util.UUID; import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.MismatchedTokenException; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.CommonTree; +import org.antlr.runtime.tree.RewriteCardinalityException; import org.eclipse.linuxtools.ctf.parser.CTFLexer; import org.eclipse.linuxtools.ctf.parser.CTFParser; import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return; @@ -177,10 +177,10 @@ public class Metadata { tempException = new CTFReaderException(e); } catch (ParseException e) { tempException = new CTFReaderException(e); - } catch (MismatchedTokenException e) { - tempException = new CtfAntlrException(e); } catch (RecognitionException e) { tempException = new CtfAntlrException(e); + } catch (RewriteCardinalityException e){ + tempException = new CtfAntlrException(e); } /* Ghetto resource management. Java 7 will deliver us from this... */ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/CtfAntlrException.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/CtfAntlrException.java index e23d2539d0..b918af008a 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/CtfAntlrException.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/exceptions/CtfAntlrException.java @@ -17,6 +17,7 @@ import java.lang.reflect.Field; import org.antlr.runtime.MismatchedTokenException; import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.tree.RewriteCardinalityException; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.parser.CTFLexer; @@ -40,7 +41,6 @@ public class CtfAntlrException extends CTFReaderException { private String fActualName = ""; //$NON-NLS-1$ private int fActualValue = -1; - /** * Re-throw the exception but read its data * @@ -59,13 +59,25 @@ public class CtfAntlrException extends CTFReaderException { * @param e * the previous recognition exception (Antlr specific) */ - public CtfAntlrException(MismatchedTokenException e){ + public CtfAntlrException(MismatchedTokenException e) { super(e); this.fErrorLine = e.line; this.fFile = "metadata"; //$NON-NLS-1$ // we're in CTF, the only thing using antlr is metadata parseMismatchedException(e); } + /** + * Re-throw the exception but read its data + * + * @param e + * the previous rewrite exception (Antlr specific) + */ + public CtfAntlrException(RewriteCardinalityException e) { + super(e); + this.fErrorLine = -1; + this.fFile = "metadata"; //$NON-NLS-1$ // we're in CTF, the only thing using antlr is metadata + } + private void parseMismatchedException(MismatchedTokenException m) { // Iterate through the tokens that are hidden in the CTFLexer // They are private static final int fields.