Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.execution;
 
 
 
 import java.util.List;
 
 import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
 
 public class ExecutionFailureInfo
 {
     private static final Pattern STACK_TRACE_PATTERN = Pattern.compile("(.*)\\.(.*)\\(([^:]*)(?::(.*))?\\)");
 
     private final String type;
     private final String message;
     private final ExecutionFailureInfo cause;
     private final List<ExecutionFailureInfosuppressed;
     private final List<Stringstack;
     private final ErrorLocation errorLocation;
     private final ErrorCode errorCode;
 
     @JsonCreator
     public ExecutionFailureInfo(
             @JsonProperty("type"String type,
             @JsonProperty("message"String message,
             @JsonProperty("cause"ExecutionFailureInfo cause,
             @JsonProperty("suppressed"List<ExecutionFailureInfosuppressed,
             @JsonProperty("stack"List<Stringstack,
             @JsonProperty("errorLocation") @Nullable ErrorLocation errorLocation,
             @JsonProperty("errorCode") @Nullable ErrorCode errorCode)
     {
         Preconditions.checkNotNull(type"type is null");
         Preconditions.checkNotNull(suppressed"suppressed is null");
         Preconditions.checkNotNull(stack"stack is null");
 
         this. = type;
         this. = message;
         this. = cause;
         this. = ImmutableList.copyOf(suppressed);
         this. = ImmutableList.copyOf(stack);
         this. = errorLocation;
         this. = errorCode;
     }
 
     @NotNull
     @JsonProperty
     public String getType()
     {
         return ;
     }
 
     @Nullable
     @JsonProperty
     public String getMessage()
     {
         return ;
     }
 
     @Nullable
     @JsonProperty
     public ExecutionFailureInfo getCause()
     {
         return ;
     }
 
     @NotNull
     @JsonProperty
     {
         return ;
     }
 
     @NotNull
     @JsonProperty
    public List<StringgetStack()
    {
        return ;
    }
    @Nullable
    {
        return ;
    }
    @Nullable
    public ErrorCode getErrorCode()
    {
        return ;
    }
    public FailureInfo toFailureInfo()
    {
        List<FailureInfosuppressed = this..stream()
                .map(ExecutionFailureInfo::toFailureInfo)
                .collect(toImmutableList());
        return new FailureInfo( == null ? null : .toFailureInfo(), suppressed);
    }
    public RuntimeException toException()
    {
        return toException(this);
    }
    private static Failure toException(ExecutionFailureInfo executionFailureInfo)
    {
        if (executionFailureInfo == null) {
            return null;
        }
        Failure failure = new Failure(executionFailureInfo.getType(), executionFailureInfo.getMessage(), executionFailureInfo.getErrorCode(), toException(executionFailureInfo.getCause()));
        for (ExecutionFailureInfo suppressed : executionFailureInfo.getSuppressed()) {
            failure.addSuppressed(toException(suppressed));
        }
        ImmutableList.Builder<StackTraceElementstackTraceBuilder = ImmutableList.builder();
        for (String stack : executionFailureInfo.getStack()) {
            stackTraceBuilder.add(toStackTraceElement(stack));
        }
        ImmutableList<StackTraceElementstackTrace = stackTraceBuilder.build();
        failure.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()]));
        return failure;
    }
    public static StackTraceElement toStackTraceElement(String stack)
    {
        Matcher matcher = .matcher(stack);
        if (matcher.matches()) {
            String declaringClass = matcher.group(1);
            String methodName = matcher.group(2);
            String fileName = matcher.group(3);
            int number = -1;
            if (fileName.equals("Native Method")) {
                fileName = null;
                number = -2;
            }
            else if (matcher.group(4) != null) {
                number = Integer.parseInt(matcher.group(4));
            }
            return new StackTraceElement(declaringClassmethodNamefileNamenumber);
        }
        return new StackTraceElement("Unknown"stacknull, -1);
    }
New to GrepCode? Check out our FAQ X