Here developers can talk about how to write a Parser for LogMX

Moderator: admin

Posts: 1
Joined: Tue Jun 30, 2015 4:06 pm


Postby mrgs123 » Tue Jun 30, 2015 4:15 pm

Hi, I run your sample parser up in eclipse, after adding a junit wrapper, and I call it thus:
public void testParseLine() {
String line1 = "07/03/2007, 16:51:00 (T0+1834ms) | ERROR | | A simple text on a single line";
String line2 = "07/03/2007, 16:51:01 (T0+2805ms) | INFO | | A simple text on";
String line3 = "two lines";
String line4 = "7/03/2007, 16:51:02 (T0+3810ms) | WARNING | | A simple text on a single line";

SampleParser P = new SampleParser();
try {
} catch (Exception e) {
fail("Exception thrown.");

and on line2, it throws a NullPointerException when it hits add_entry(entry); for the first time...

What am I doing wrong?


Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Re: NullPointerException

Postby admin » Tue Jun 30, 2015 6:57 pm


This error occurs because the entries list for this Parser has not been created yet: Parsers need to be initialized before being used (that's what LogMX do). Because it is an internal mechanism, it is not very easy for you to create this list: the required method is obfuscated (i.e. renamed with a random method name like "a", "b", "dF", ... just before the release). For LogMX v5.3.4 eval version, this method is called "a()". You can recognize this method in any other version knowing that it has package-protected access, and takes a single "List" as parameter. So here is a way to make your code work:

Code: Select all

LogFileParser P = new SampleParser();
P.a(new ArrayList());

Notes: You need to declare P as a "LogFileParser" and not "SampleParser", and to bypass the issue of obfuscated code for the type of List, you can just create a raw type List (i.e. "ArrayList()" instead of "ArrayList<j>()" because "j" can change in future releases).

But maybe we should set this method as public without any obfuscation, for people like you who want to do Unit Tests (which is a very good idea :wink: ). What do you think?


Return to “Writing a Parser”

Who is online

Users browsing this forum: No registered users and 1 guest