class ModelBuildingException extends Exception {

    private final ModelBuildingResult result;

    /**
     * Creates a new exception with the specified problems.
     *
     * @param model The model that could not be built, may be {@code null}.
     * @param modelId The identifier of the model that could not be built, may be {@code null}.
     * @param problems The problems that cause this exception, may be {@code null}.
     * @deprecated Use {@link #ModelBuildingException(ModelBuildingResult)} instead.
     */
    @Deprecated
    public ModelBuildingException(Model model, String modelId, List<ModelProblem> problems) {
        super(toMessage(modelId, problems));

        if (model != null) {
            DefaultModelBuildingResult tmp = new DefaultModelBuildingResult();
            if (modelId == null) {
                modelId = "";
            }
            tmp.addModelId(modelId);
            tmp.setRawModel(modelId, model);
            tmp.setProblems(problems);
            result = tmp;
        } else {
            result = null;
        }
    }

    /**
     * Creates a new exception from the specified interim result and its associated problems.
     *
     * @param result The interim result, may be {@code null}.
     */
    public ModelBuildingException(ModelBuildingResult result) {
        super(toMessage(result));
        this.result = result;
    }

    /**
     * Gets the interim result of the model building up to the point where it failed.
     *
     * @return The interim model building result or {@code null} if not available.
     */
    public ModelBuildingResult getResult() {
        return result;
    }

    /**
     * Gets the model that could not be built properly.
     *
     * @return The erroneous model or {@code null} if not available.
     */
    public Model getModel() {
        if (result == null) {
            return null;
        }
        if (result.getEffectiveModel() != null) {
            return result.getEffectiveModel();
        }
        return result.getRawModel();
    }

    /**
     * Gets the identifier of the POM whose effective model could not be built. The general format of the identifier is
     * {@code <groupId>:<artifactId>:<version>} but some of these coordinates may still be unknown at the point the
     * exception is thrown so this information is merely meant to assist the user.
     *
     * @return The identifier of the POM or an empty string if not known, never {@code null}.
     */
    public String getModelId() {
        if (result == null || result.getModelIds().isEmpty()) {
            return "";
        }
        return result.getModelIds().get(0);
    }

    /**
     * Gets the problems that caused this exception.
     *
     * @return The problems that caused this exception, never {@code null}.
     */
    public List<ModelProblem> getProblems() {
        if (result == null) {
            return Collections.emptyList();
        }
        return Collections.unmodifiableList(result.getProblems());
    }

    private static String toMessage(ModelBuildingResult result) {
        if (result != null && !result.getModelIds().isEmpty()) {
            return toMessage(result.getModelIds().get(0), result.getProblems());
        }
        return null;
    }

    // Package protected for test
    static String toMessage(String modelId, List<ModelProblem> problems) {<FILL_FUNCTION_BODY>}
}

        StringWriter buffer = new StringWriter(1024);

        PrintWriter writer = new PrintWriter(buffer);

        writer.print(problems.size());
        writer.print((problems.size() == 1) ? " problem was " : " problems were ");
        writer.print("encountered while building the effective model");
        if (modelId != null && !modelId.isEmpty()) {
            writer.print(" for ");
            writer.print(modelId);
        }

        for (ModelProblem problem : problems) {
            writer.println();
            writer.print("    - [");
            writer.print(problem.getSeverity());
            writer.print("] ");
            writer.print(problem.getMessage());
            String location = ModelProblemUtils.formatLocation(problem, modelId);
            if (!location.isEmpty()) {
                writer.print(" @ ");
                writer.print(location);
            }
        }

        return buffer.toString();
    
<methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.Throwable) ,public void <init>(java.lang.String, java.lang.Throwable) <variables>static final long serialVersionUID