L2JMobius

High Five Adding new script and diagnostic.getSource() Null

uchihasv · 2 · 1955

Offline uchihasv

  • Knight
  • ***
    • Posts: 54
Hello i try add some missing scripts like Mobs AI, and i put in scripts/ai/others/new/new.java

And i use correct imports for this and methods like others, but when loading i get NPE:
Code: [Select]
Failed to execute script list!
java.lang.NullPointerException: Cannot invoke "javax.tools.JavaFileObject.getName()" because the return value of "javax.tools.Diagnostic.getSource()" is null
at org.l2jmobius.gameserver.scripting.java.JavaExecutionContext.executeScripts(JavaExecutionContext.java:166)

Java Execution Context:
Code: [Select]
out.println("-----------------------");
out.println("Compilation diagnostics");
out.println("-----------------------");
for (Diagnostic<? extends JavaFileObject> diagnostic : compilationDiagnostics.getDiagnostics())
{
out.println("\t" + diagnostic.getKind() + ": " + diagnostic.getSource().getName() + ", Line " + diagnostic.getLineNumber() + ", Column " + diagnostic.getColumnNumber());
out.println("\t\tcode: " + diagnostic.getCode());
out.println("\t\tmessage: " + diagnostic.getMessage(null));
}

I think debugger try get source line and name to output, but in diagnostic.getSource() get Null instead of script code, why?

I try search about this in StackOverflow and some Java users say it's maybe can be if java run in JRE instead of JDK, but i use Bellsoft OpenJDK(from l2jmobius bitbucket readme.txt).

Has anyone had problems with this?

I remember that I faced this problem before and the temporary solution was to comment out this line, but maybe there is another normal solution?


Offline uchihasv

  • Knight
  • ***
    • Posts: 54
My temp fix for this problem is add some checking to null in diagnostic.getSource():
Code: [Select]
String diagnosticSourceName = (diagnostic.getSource() != null)? diagnostic.getSource().getName() : "";