cmusphinx / sphinx4

Pure Java speech recognition library
cmusphinx.sourceforge.net
Other
1.41k stars 586 forks source link

Fix NullPointerException with null logMath when using weighted JSGF grammars #53

Closed karbachinsky closed 8 years ago

karbachinsky commented 8 years ago

I have a JSGF grammar with weights.

And got exception when using this grammar. The problem is that JSGFGrammar is initialized with default constructor in FlatLinguist and logMath reamins null.

java.lang.NullPointerException
    at edu.cmu.sphinx.jsgf.JSGFGrammar.getNormalizedWeights(JSGFGrammar.java:493)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleAlternatives(JSGFGrammar.java:448)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:333)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleName(JSGFGrammar.java:392)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:337)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleSequence(JSGFGrammar.java:520)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:339)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleAlternatives(JSGFGrammar.java:458)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:333)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleCount(JSGFGrammar.java:414)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:335)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleSequence(JSGFGrammar.java:520)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:339)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRuleAlternatives(JSGFGrammar.java:458)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.processRule(JSGFGrammar.java:333)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.commitChanges(JSGFGrammar.java:636)
    at edu.cmu.sphinx.jsgf.JSGFGrammar.createGrammar(JSGFGrammar.java:298)
    at edu.cmu.sphinx.linguist.language.grammar.Grammar.allocate(Grammar.java:112)
    at edu.cmu.sphinx.linguist.flat.FlatLinguist.allocate(FlatLinguist.java:264)
    at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstSearchManager.allocate(WordPruningBreadthFirstSearchManager.java:243)
    at edu.cmu.sphinx.decoder.AbstractDecoder.allocate(AbstractDecoder.java:103)
    at edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:164)
        ...
karbachinsky commented 8 years ago

I forgot to mark init() as protected, sorry.

nshmyrev commented 8 years ago

Thank you for the report.

Application should never create grammar with default constructor without calling newProperties. It leads to more serious issues than just missing logMath. Someone has to look why it happens.

karbachinsky commented 8 years ago

Ok, I'll try to check.

nshmyrev commented 8 years ago

Fixed in a bit different way, thank you.

nshmyrev commented 8 years ago

Also in sf tracker https://sourceforge.net/p/cmusphinx/bugs/428/