#3879 NPE occurs in TokenMaker

severe bug
open
nobody
None
5
2014-08-14
2014-08-01
Meg
No

jEdit version: 5.1.0
platform: CentOs 5.10
Java version: 1.6.0_45
steps to reproduce:

public void test450() throws Throwable {
org.gjt.sp.jedit.buffer.JEditBuffer var0 = new org.gjt.sp.jedit.buffer.JEditBuffer();
org.gjt.sp.jedit.syntax.TokenMarker var4 = var0.getTokenMarker();
org.gjt.sp.jedit.syntax.TokenMarker.LineContext var6 = new org.gjt.sp.jedit.syntax.TokenMarker.LineContext();
org.gjt.sp.jedit.syntax.DefaultTokenHandler var8 = new org.gjt.sp.jedit.syntax.DefaultTokenHandler();
org.gjt.sp.util.SegmentBuffer var10 = new org.gjt.sp.util.SegmentBuffer(32768);
org.gjt.sp.jedit.syntax.TokenMarker.LineContext var12 = var4.markTokens(var6, (org.gjt.sp.jedit.syntax.TokenHandler)var8, (javax.swing.text.Segment)var10);
}

Expected result: No NPE
StackTrace:
88) test450(RandoopTest0)java.lang.NullPointerException
at org.gjt.sp.jedit.syntax.TokenMarker.markTokens(TokenMarker.java:120)
at RandoopTest0.test450(RandoopTest0.java:8709)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Discussion

  • Meg
    Meg
    2014-08-14

    public synchronized LineContext markTokens(LineContext prevContext,
        TokenHandler tokenHandler, Segment line)
    {
        ...
    
        context = new LineContext();
    
        if(prevContext == null)
        {
            context.rules = getMainRuleSet();
            context.escapeRule = context.rules.getEscapeRule();
        }
        else
        {
            context.parent = prevContext.parent;
            context.setInRule(prevContext.inRule);
            context.rules = prevContext.rules;
            context.spanEndSubst = prevContext.spanEndSubst;
            context.spanEndSubstRegex = prevContext.spanEndSubstRegex;
        }
    
        keywords = context.rules.getKeywords(); --> NPE
        ...
    }
    

    context.rules is assigned in both branches before the refrence. Although context.rule can be null, there is no proper error handling before use.

     
    Last edit: Meg 2014-08-14