0

I'm working on a Java library that has an annotation processor. To trap exceptions I wrote code similar to the following code:

public class KriptonProcessor extends AbstractProcessor {

  @Override
  public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
    try {
        ...
        return true;
    } catch (Throwable e) {
        String msg = StringUtils.nvl(e.getMessage());
        error(null, e.getClass().getCanonicalName() + ": " + msg);
        e.printStackTrace();

    }

    return true;
  }
}

When an exception occurs, actually it's displayed as:

e: error: java.lang.NullPointerException:

While I was expecting the full stack trace, useful to detect where is the problem. Any ideas to accomplish this task?

Thanks in advance.

xcesco
  • 4,690
  • 4
  • 34
  • 65
  • Are you able to put a breakpoint in your catch block using using a debugger? You should be able examine the contents of your Throwable object to check for the backtrace. https://stackoverflow.com/questions/2411487/nullpointerexception-in-java-with-no-stacktrace – sc_ray Jul 31 '18 at 22:07
  • No, the error occurs at compile time. Breakpoint work within the program. – xcesco Jul 31 '18 at 22:27

1 Answers1

-1
public class KriptonProcessor extends AbstractProcessor {

  @Override
  public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
    try {
        ...
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;

    }

    return true;
  }
}
Dan
  • 979
  • 1
  • 8
  • 29