thekrakken / java-grok

Simple API that allows you to easily parse logs and other files
http://grok.nflabs.com/
Other
358 stars 152 forks source link

Match is a singleton, which creates very weird behavior. #21

Closed wouterdb closed 1 year ago

wouterdb commented 9 years ago

Hi,

When I have multiple instances of grok, or even just use grok in a loop grok behaves very odd, because of Match being a singleton.

For example, If I use the same grok pattern twice and grok matches the first time, but not the second time, then the second time returns a match nontheless.

in the code (Grok.java: 250-260)

Match match = Match.getInstance(); if (m.find()) { match.setSubject(text); match.setGrok(this); match.setMatch(m); match.setStart(m.start(0)); match.setEnd(m.end(0)); } return match;

So, the first time m.find is true and the singleton is filled with values the second time m.find is false, so, even tough there is no match it remains filled with values

I can see no reason why Match should be a singleton and propose that it becomes a normal class.

I can submit a patch is required.

anthonycorbacho commented 9 years ago

Hi,

Thank you for the feedback, and you point make total sense to me. I created a PR #22 If it is good for you, i will merge it.

wouterdb commented 9 years ago

Hi,

I've just seen that this bug is not in you code at all! I'm sorry, I was mixing the nflabs repo with this one. You have fixed it already in aa77b41b1fa2d5c81abddf5380f45d1d3d6da2eb

My bad