package no.rosbach.jcoru.rest.reports;

import javax.tools.Diagnostic;
import javax.tools.SimpleJavaFileObject;
import javax.xml.bind.annotation.XmlTransient;

public class CompilationReportEntry {
  public String message;
  public String code;
  public long lineNumber;
  public long columnNumber;
  public String sourceName;
  private Diagnostic.Kind kind;

  public CompilationReportEntry() {

  }

  /**
   * Create a complete report entry from Diagnostic.
   *
   * @param diagnostic the diagnostic.
   */
  public CompilationReportEntry(Diagnostic<? extends SimpleJavaFileObject> diagnostic) {
    message = diagnostic.getMessage(null);
    code = diagnostic.getCode();
    kind = diagnostic.getKind();
    lineNumber = diagnostic.getLineNumber();
    columnNumber = diagnostic.getColumnNumber();
    sourceName = diagnostic.getSource().getName();
  }

  public String getKind() {
    return kind.name();
  }

  public void setKind(String kind) {
    this.kind = Diagnostic.Kind.valueOf(kind);
  }

  @XmlTransient
  public Diagnostic.Kind getDiagnosticKind() {
    return kind;
  }
}

@@ -151,16 +151,43 @@
 ansient;
+%0Aimport java.util.Optional;
 %0A%0Apublic
@@ -628,59 +628,198 @@
     
-message = diagnostic.getMessage(null);%0A    code = d
+Optional%3C? extends Diagnostic%3C? extends SimpleJavaFileObject%3E%3E optional = Optional.of(diagnostic);%0A    message = optional.map(d -%3E d.getMessage(null)).orElse(null);%0A    code = optional.map(D
 iagn
@@ -827,17 +827,30 @@
 stic
-.
+::
 getCode
-(
+).orElse(null
 );%0A 
@@ -859,17 +859,30 @@
  kind = 
-d
+optional.map(D
 iagnosti
@@ -886,17 +886,30 @@
 stic
-.
+::
 getKind
-(
+).orElse(null
 );%0A 
@@ -916,33 +916,46 @@
    lineNumber = 
-d
+optional.map(D
 iagnostic.getLin
@@ -947,17 +947,18 @@
 agnostic
-.
+::
 getLineN
@@ -958,25 +958,37 @@
 etLineNumber
-(
+).orElse(null
 );%0A    colum
@@ -997,17 +997,30 @@
 umber = 
-d
+optional.map(D
 iagnosti
@@ -1020,17 +1020,18 @@
 agnostic
-.
+::
 getColum
@@ -1037,17 +1037,29 @@
 mnNumber
-(
+).orElse(null
 );%0A    s
@@ -1070,17 +1070,30 @@
 eName = 
-d
+optional.map(D
 iagnosti
@@ -1093,17 +1093,18 @@
 agnostic
-.
+::
 getSourc
@@ -1108,19 +1108,56 @@
 urce
-(
 ).
-getName(
+map(SimpleJavaFileObject::getName).orElse(null
 );%0A 

Make CompilationReportEntry NPE safe