0

I've disassembled a .jar file and ended up with some files that invoke a constructor:

public Interface_inheritance_specContext(ParserRuleContext parent, int invokingState) { super(invokingState); }

with the following implementation:

public ParserRuleContext(@Nullable ParserRuleContext parent, int invokingStateNumber) {
        super(parent, invokingStateNumber);
    }

Upon compilation the following error is given:

Error:(199, 92) java: no suitable constructor found for ParserRuleContext(int)
    constructor org.antlr.v4.runtime.ParserRuleContext.ParserRuleContext() is not applicable
      (actual and formal argument lists differ in length)
    constructor org.antlr.v4.runtime.ParserRuleContext.ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext,int) is not applicable
      (actual and formal argument lists differ in length)

Looking over this question I don't see any answers that consider @Nullable parameters. The constructor is located in a separate .jar file and I as hoping that I wouldn't have to disassemble it as well.

I noticed that, by adding an extra null parameter solves the issue. But why is the error given in the first place?

Community
  • 1
  • 1
Sebi
  • 4,262
  • 13
  • 60
  • 116

1 Answers1

3

The constructor of ParserRuleContext that you pasted in your question is not a vararg constructor, but it is a constructor which accepts two parameters and @Nullable just mentions that the first parameter can be null.

Hence when you just invoke a constructor with one parameter it doesn't recognize a single parameter constructor, and hence the error.

Bajji
  • 2,243
  • 2
  • 22
  • 35