Hi, I run your sample parser up in eclipse, after adding a junit wrapper, and I call it thus:
@Test
public void testParseLine() {
String line1 = "07/03/2007, 16:51:00 (T0+1834ms) | ERROR | com.company.soft.DatabaseManager | A simple text on a single line";
String line2 = "07/03/2007, 16:51:01 (T0+2805ms) | INFO | com.company.soft.gui.MainFrame | A simple text on";
String line3 = "two lines";
String line4 = "7/03/2007, 16:51:02 (T0+3810ms) | WARNING | com.company.soft.gui.MainFrame | A simple text on a single line";
SampleParser P = new SampleParser();
try {
P.parseLine(line1);
P.parseLine(line2);
P.parseLine(line3);
P.parseLine(line4);
P.parseLine(null);
} 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?
Cheers,
mrgs
NullPointerException
Moderator: admin
Re: NullPointerException
Hello,
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 does). 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:
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
). What do you think?
Xavier
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 does). 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());
P.parseLine(line1);
P.parseLine(line2);
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 :wink:](./images/smilies/icon_e_wink.gif)
Xavier
Re: NullPointerException
+1 for me.
I have observed this problem too and would love if you could make the function public. Using Junit when writing custom parser simplifies things a lot.
BR;
-Martin
I have observed this problem too and would love if you could make the function public. Using Junit when writing custom parser simplifies things a lot.
BR;
-Martin
Re: NullPointerException
Hello,
OK, since there is clearly a need, we will add it in the next version (v8.0)
(probably a "init()" public method to prepare the Parser if not already initialized).
We will let you know when it's available!
Thanks for your feedback.
Xavier
OK, since there is clearly a need, we will add it in the next version (v8.0)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
We will let you know when it's available!
Thanks for your feedback.
Xavier
Re: NullPointerException
Hello,
As promised, LogMX v8.0.0 is now available for download, and includes the new method "LogFileParser.init()"
: https://logmx.com/dev/api/com/lightysof ... tml#init--
Let me know if you have any questions!
Xavier
As promised, LogMX v8.0.0 is now available for download, and includes the new method "LogFileParser.init()"
![Smile :)](./images/smilies/icon_e_smile.gif)
Let me know if you have any questions!
Xavier