Example usage for java.lang InstantiationException getMessage

List of usage examples for java.lang InstantiationException getMessage

Introduction

In this page you can find the example usage for java.lang InstantiationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.naryx.tagfusion.cfm.xml.ws.javaplatform.DynamicWebServiceStubGenerator.java

private Stub createStubInstance(DynamicCacheClassLoader cl, String wsdlURL) throws cfmRunTimeException {
    Stub stub = null;//from  ww  w .ja  va2 s . c  o m
    Object locator = null;

    // Get the locator
    Class[] klasses = cl.findAllClasses();
    for (int i = 0; i < klasses.length; i++) {
        if (klasses[i].getName().endsWith(this.si.getLocatorName())
                && org.apache.axis.client.Service.class.isAssignableFrom(klasses[i])) {
            try {
                // Create the service
                locator = klasses[i].newInstance();
                break;
            } catch (InstantiationException ex) {
                throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                        "Invalid service locator generated for " + wsdlURL + ". Cannot create locator. "
                                + ex.getMessage()));
            } catch (IllegalAccessException ex) {
                throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                        "Invalid service locator generated for " + wsdlURL + ". Cannot access locator. "
                                + ex.getMessage()));
            }
        }
    }

    // Make sure we got it.
    if (locator == null)
        throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                "Invalid service locator generated for " + wsdlURL + ". Cannot find locator: "
                        + this.si.getLocatorName()));

    // Get a stub from the locator
    try {
        Method stubMethod = locator.getClass().getDeclaredMethod("get" + this.si.getStubName(), new Class[0]);
        stub = (Stub) stubMethod.invoke(locator, new Object[0]);
    } catch (NoSuchMethodException ex) {
        throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                "Invalid service locator generated for " + wsdlURL + ". No method: " + "get"
                        + this.si.getStubName() + " not found."));
    } catch (IllegalAccessException ex) {
        throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                "Invalid service locator generated for " + wsdlURL + ". Cannot access method: " + "get"
                        + this.si.getStubName()));
    } catch (InvocationTargetException ex) {
        throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                "Invalid service locator generated for " + wsdlURL + ". Cannot invoke method: " + "get"
                        + this.si.getStubName() + ". " + ex.getMessage() + " "
                        + ex.getTargetException().getMessage()));
    }

    return stub;
}

From source file:com.google.gsa.valve.rootAuth.RootAuthorizationProcess.java

/**
 * Gets the authorization process instance needed to process the request
 * //from   www  .  j  av  a 2  s .com
 * @param repository the repository configuration information
 * 
 * @return the authorization class 
 */
private AuthorizationProcessImpl getAuthorizationProcess(ValveRepositoryConfiguration repository) {

    AuthorizationProcessImpl authProcess = null;

    //protection
    if (repository != null) {

        try {

            String authZComponent = repository.getAuthZ();
            logger.debug("Authorization module is: " + authZComponent);

            if (authZComponent != null) {
                authProcess = (AuthorizationProcessImpl) Class.forName(authZComponent).newInstance();
                authProcess.setValveConfiguration(valveConf);
            } else {
                logger.debug("This repository[" + repository.getId()
                        + "] does not cointain any Authorization class");
            }

        } catch (LinkageError le) {
            logger.error(repository.getId() + " - Can't instantiate class [AuthorizationProcess-LinkageError]: "
                    + le.getMessage(), le);
            authProcess = null;
        } catch (InstantiationException ie) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthorizationProcess-InstantiationException]: "
                    + ie.getMessage(), ie);
            authProcess = null;
        } catch (IllegalAccessException iae) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthorizationProcess-IllegalAccessException]: "
                    + iae.getMessage(), iae);
            authProcess = null;
        } catch (ClassNotFoundException cnfe) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthorizationProcess-ClassNotFoundException]: "
                    + cnfe.getMessage(), cnfe);
            authProcess = null;
        } catch (Exception e) {
            logger.error(repository.getId() + " - Can't instantiate class [AuthorizationProcess-Exception]: "
                    + e.getMessage(), e);
            authProcess = null;
        }
    }

    return authProcess;
}

From source file:de.cenote.jasperstarter.Report.java

private Map<String, Object> getCmdLineReportParams() {
    JRParameter[] jrParameterArray = jasperReport.getParameters();
    Map<String, JRParameter> jrParameters = new HashMap<String, JRParameter>();
    Map<String, Object> parameters = new HashMap<String, Object>();
    List<String> params;
    if (config.hasParams()) {
        params = config.getParams();/*from w  ww  .  j a v  a 2s.c om*/
        for (JRParameter rp : jrParameterArray) {
            jrParameters.put(rp.getName(), rp);
        }
        String paramName = null;
        //String paramType = null;
        String paramValue = null;

        for (String p : params) {
            try {
                paramName = p.split("=")[0];
                paramValue = p.split("=", 2)[1];
                if (config.isVerbose()) {
                    System.out.println("Using report parameter: " + paramName + " = " + paramValue);
                }
            } catch (Exception e) {
                throw new IllegalArgumentException("Wrong report param format! " + p, e);
            }
            if (!jrParameters.containsKey(paramName)) {
                throw new IllegalArgumentException("Parameter '" + paramName + "' does not exist in report!");
            }

            JRParameter reportParam = jrParameters.get(paramName);

            try {
                // special parameter handlers must also implemeted in
                // ParameterPanel.java
                if (Date.class.equals(reportParam.getValueClass())) {
                    // Date must be in ISO8601 format. Example 2012-12-31
                    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd");
                    parameters.put(paramName, (Date) dateFormat.parse(paramValue));
                } else if (Image.class.equals(reportParam.getValueClass())) {
                    Image image = Toolkit.getDefaultToolkit()
                            .createImage(JRLoader.loadBytes(new File(paramValue)));
                    MediaTracker traker = new MediaTracker(new Panel());
                    traker.addImage(image, 0);
                    try {
                        traker.waitForID(0);
                    } catch (Exception e) {
                        throw new IllegalArgumentException("Image tracker error: " + e.getMessage(), e);
                    }
                    parameters.put(paramName, image);
                } else if (Locale.class.equals(reportParam.getValueClass())) {
                    parameters.put(paramName, LocaleUtils.toLocale(paramValue));
                } else {
                    // handle generic parameters with string constructor
                    try {
                        parameters.put(paramName, reportParam.getValueClass().getConstructor(String.class)
                                .newInstance(paramValue));
                    } catch (InstantiationException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused " + ex.getClass().getName()
                                + " " + ex.getMessage(), ex);
                    } catch (IllegalAccessException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused " + ex.getClass().getName()
                                + " " + ex.getMessage(), ex);
                    } catch (InvocationTargetException ex) {
                        Throwable cause = ex.getCause();
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused "
                                + cause.getClass().getName() + " " + cause.getMessage(), cause);
                    } catch (NoSuchMethodException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " with value '" + paramValue
                                + "' is not supported by JasperStarter!", ex);
                    }
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(
                        "NumberFormatException: " + e.getMessage() + "\" in \"" + p + "\"", e);
            } catch (java.text.ParseException e) {
                throw new IllegalArgumentException(e.getMessage() + "\" in \"" + p + "\"", e);
            } catch (JRException e) {
                throw new IllegalArgumentException("Unable to load image from: " + paramValue, e);
            }
        }
    }
    return parameters;
}

From source file:ResultSetIterator.java

/**
 * Factory method that returns a new instance of the given Class.  This
 * is called at the start of the bean creation process and may be 
 * overridden to provide custom behavior like returning a cached bean
 * instance.//from w  w w .  j  a  va  2s . c  o m
 *
 * @param c The Class to create an object from.
 * @return A newly created object of the Class.
 * @throws SQLException if creation failed.
 */
protected Object newInstance(Class c) throws SQLException {
    try {
        return c.newInstance();

    } catch (InstantiationException e) {
        throw new SQLException("Cannot create " + c.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException("Cannot create " + c.getName() + ": " + e.getMessage());
    }
}

From source file:org.codehaus.groovy.grails.plugins.DefaultGrailsPlugin.java

public void doArtefactConfiguration() {
    if (!pluginBean.isReadableProperty(ARTEFACTS)) {
        return;//from w  w w. j ava  2 s .c o  m
    }

    List l = (List) plugin.getProperty(ARTEFACTS);
    for (Object artefact : l) {
        if (artefact instanceof Class) {
            Class artefactClass = (Class) artefact;
            if (ArtefactHandler.class.isAssignableFrom(artefactClass)) {
                try {
                    application.registerArtefactHandler((ArtefactHandler) artefactClass.newInstance());
                } catch (InstantiationException e) {
                    LOG.error("Cannot instantiate an Artefact Handler:" + e.getMessage(), e);
                } catch (IllegalAccessException e) {
                    LOG.error("The constructor of the Artefact Handler is not accessible:" + e.getMessage(), e);
                }
            } else {
                LOG.error("This class is not an ArtefactHandler:" + artefactClass.getName());
            }
        } else if (artefact instanceof ArtefactHandler) {
            application.registerArtefactHandler((ArtefactHandler) artefact);
        } else {
            LOG.error("This object is not an ArtefactHandler:" + artefact + "[" + artefact.getClass().getName()
                    + "]");
        }
    }
}

From source file:er.directtoweb.pages.ERD2WListPage.java

/**
 * Attempts to instantiate the custom edit object delegate subclass, if one has been specified.
 *//*from   www  .ja v  a  2 s  . co m*/
private ERDEditObjectDelegate editObjectDelegateInstance() {
    ERDEditObjectDelegate delegate = null;
    String delegateClassName = (String) d2wContext().valueForKey("editObjectDelegateClass");
    if (delegateClassName != null) {
        try {
            Class delegateClass = Class.forName(delegateClassName);
            Constructor delegateClassConstructor = delegateClass.getConstructor(WOContext.class);
            delegate = (ERDEditObjectDelegate) delegateClassConstructor.newInstance(context());
        } catch (LinkageError le) {
            if (le instanceof ExceptionInInitializerError) {
                log.warn("Could not initialize edit object delegate class: " + delegateClassName);
            } else {
                log.warn(
                        "Could not load  delegate class: " + delegateClassName + " due to: " + le.getMessage());
            }
        } catch (ClassNotFoundException cnfe) {
            log.warn("Could not find class for edit object delegate: " + delegateClassName);
        } catch (NoSuchMethodException nsme) {
            log.warn("Could not find constructor for edit object delegate class: " + delegateClassName);
        } catch (SecurityException se) {
            log.warn(
                    "Insufficient privileges to access edit object delegate constructor: " + delegateClassName);
        } catch (IllegalAccessException iae) {
            log.warn("Insufficient access to create edit object delegate instance: " + iae.getMessage());
        } catch (IllegalArgumentException iae) {
            log.warn("Used an illegal argument when creating edit object delegate instance: "
                    + iae.getMessage());
        } catch (InstantiationException ie) {
            log.warn("Could not instantiate edit object delegate instance: " + ie.getMessage());
        } catch (InvocationTargetException ite) {
            log.warn("Exception while invoking edit object delegate constructor: " + ite.getMessage());
        }
    }

    return delegate;
}

From source file:org.apache.struts.taglib.tiles.InsertTag.java

/**
 * Get instantiated Controller./*from  www. j  av  a  2s.co m*/
 * Return controller denoted by controllerType, or <code>null</code> if controllerType
 * is null.
 * @throws JspException If controller can't be created.
 */
private Controller getController() throws JspException {
    if (controllerType == null) {
        return null;
    }

    try {
        return ComponentDefinition.createController(controllerName, controllerType);

    } catch (InstantiationException ex) {
        throw new JspException(ex.getMessage());
    }
}

From source file:org.apache.struts.taglib.tiles.InsertTag.java

/**
 * End of Process tag attribute "definition".
 * Overload definition with tag attributes "template" and "role".
 * Then, create appropriate tag handler.
 * @param definition Definition to process.
 * @return Appropriate TagHandler.//from   w w w.j  a v a2s.co m
 * @throws JspException InstantiationException Can't create requested controller
 */
protected TagHandler processDefinition(ComponentDefinition definition) throws JspException {
    // Declare local variable in order to not change Tag attribute values.
    String role = this.role;
    String page = this.page;
    Controller controller = null;

    try {
        controller = definition.getOrCreateController();

        // Overload definition with tag's template and role.
        if (role == null) {
            role = definition.getRole();
        }

        if (page == null) {
            page = definition.getTemplate();
        }

        if (controllerName != null) {
            controller = ComponentDefinition.createController(controllerName, controllerType);
        }

        // Can check if page is set
        return new InsertHandler(definition.getAttributes(), page, role, controller);

    } catch (InstantiationException ex) {
        throw new JspException(ex.getMessage());
    }
}

From source file:org.grails.plugins.DefaultGrailsPlugin.java

public void doArtefactConfiguration() {
    if (!pluginBean.isReadableProperty(ARTEFACTS)) {
        return;/* w  w  w  .  j a v a 2  s .  co m*/
    }

    List l;
    if (plugin instanceof Plugin) {
        l = ((Plugin) plugin).getArtefacts();
    } else {

        l = (List) plugin.getProperty(ARTEFACTS);
    }
    for (Object artefact : l) {
        if (artefact instanceof Class) {
            Class artefactClass = (Class) artefact;
            if (ArtefactHandler.class.isAssignableFrom(artefactClass)) {
                try {
                    ((LegacyGrailsApplication) application).getGrailsApplication()
                            .registerArtefactHandler((ArtefactHandler) artefactClass.newInstance());
                } catch (InstantiationException e) {
                    LOG.error("Cannot instantiate an Artefact Handler:" + e.getMessage(), e);
                } catch (IllegalAccessException e) {
                    LOG.error("The constructor of the Artefact Handler is not accessible:" + e.getMessage(), e);
                }
            } else {
                LOG.error("This class is not an ArtefactHandler:" + artefactClass.getName());
            }
        } else if (artefact instanceof ArtefactHandler) {
            ((LegacyGrailsApplication) application).getGrailsApplication()
                    .registerArtefactHandler((ArtefactHandler) artefact);
        } else {
            LOG.error("This object is not an ArtefactHandler:" + artefact + "[" + artefact.getClass().getName()
                    + "]");
        }
    }
}

From source file:com.rapidminer.operator.learner.functions.linear.LinearRegression.java

@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
    // initializing data and parameter values.
    Attribute label = exampleSet.getAttributes().getLabel();
    Attribute workingLabel = label;
    boolean cleanUpLabel = false;
    String firstClassName = null;
    String secondClassName = null;

    com.rapidminer.example.Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this,
            Attributes.LABEL_NAME);

    boolean useBias = getParameterAsBoolean(PARAMETER_USE_BIAS);
    boolean removeColinearAttributes = getParameterAsBoolean(PARAMETER_ELIMINATE_COLINEAR_FEATURES);
    double ridge = getParameterAsDouble(PARAMETER_RIDGE);
    double minTolerance = getParameterAsDouble(PARAMETER_MIN_TOLERANCE);

    // prepare for classification by translating into 0-1 coding.
    if (label.isNominal()) {
        if (label.getMapping().size() == 2) {
            firstClassName = label.getMapping().getNegativeString();
            secondClassName = label.getMapping().getPositiveString();

            int firstIndex = label.getMapping().getNegativeIndex();

            workingLabel = AttributeFactory.createAttribute("regression_label", Ontology.REAL);
            exampleSet.getExampleTable().addAttribute(workingLabel);

            for (Example example : exampleSet) {
                double index = example.getValue(label);
                if (index == firstIndex) {
                    example.setValue(workingLabel, 0.0d);
                } else {
                    example.setValue(workingLabel, 1.0d);
                }/*  w ww .j  a va2  s  .c  o m*/
            }

            exampleSet.getAttributes().setLabel(workingLabel);
            cleanUpLabel = true;
        }
    }

    // search all attributes and keep numerical
    int numberOfAttributes = exampleSet.getAttributes().size();
    boolean[] isUsedAttribute = new boolean[numberOfAttributes];
    int counter = 0;
    String[] attributeNames = new String[numberOfAttributes];
    for (Attribute attribute : exampleSet.getAttributes()) {
        isUsedAttribute[counter] = attribute.isNumerical();
        attributeNames[counter] = attribute.getName();
        counter++;
    }

    // compute and store statistics and turn off attributes with zero
    // standard deviation
    exampleSet.recalculateAllAttributeStatistics();
    double[] means = new double[numberOfAttributes];
    double[] standardDeviations = new double[numberOfAttributes];
    counter = 0;
    Attribute[] allAttributes = new Attribute[exampleSet.getAttributes().size()];
    for (Attribute attribute : exampleSet.getAttributes()) {
        allAttributes[counter] = attribute;
        if (isUsedAttribute[counter]) {
            means[counter] = exampleSet.getStatistics(attribute, Statistics.AVERAGE_WEIGHTED);
            standardDeviations[counter] = Math
                    .sqrt(exampleSet.getStatistics(attribute, Statistics.VARIANCE_WEIGHTED));
            if (standardDeviations[counter] == 0) {
                isUsedAttribute[counter] = false;
            }
        }
        counter++;
    }

    double labelMean = exampleSet.getStatistics(workingLabel, Statistics.AVERAGE_WEIGHTED);
    double labelStandardDeviation = Math
            .sqrt(exampleSet.getStatistics(workingLabel, Statistics.VARIANCE_WEIGHTED));

    int numberOfExamples = exampleSet.size();

    // determine the number of used attributes + 1
    int numberOfUsedAttributes = 1;
    for (int i = 0; i < isUsedAttribute.length; i++) {
        if (isUsedAttribute[i]) {
            numberOfUsedAttributes++;
        }
    }

    // remove colinear attributes
    double[] coefficientsOnFullData = performRegression(exampleSet, isUsedAttribute, means, labelMean, ridge);
    if (removeColinearAttributes) {
        boolean eliminateMore = true;
        while (eliminateMore) {
            int maxIndex = -1;
            double maxTolerance = 1;
            boolean found = false;
            for (int i = 0; i < isUsedAttribute.length; i++) {
                if (isUsedAttribute[i]) {
                    double tolerance = getTolerance(exampleSet, isUsedAttribute, i, ridge, useBias);
                    if (tolerance < minTolerance) {
                        if (tolerance <= maxTolerance) {
                            maxTolerance = tolerance;
                            maxIndex = i;
                            found = true;
                        }
                    }
                }
            }
            if (found) {
                isUsedAttribute[maxIndex] = false;
            } else {
                eliminateMore = false;
            }
            coefficientsOnFullData = performRegression(exampleSet, isUsedAttribute, means, labelMean, ridge);
        }
    } else {
        coefficientsOnFullData = performRegression(exampleSet, isUsedAttribute, means, labelMean, ridge);
    }

    // calculate error on full data
    double errorOnFullData = getSquaredError(exampleSet, isUsedAttribute, coefficientsOnFullData, useBias);

    // apply attribute selection method

    int selectionMethodIndex = getParameterAsInt(PARAMETER_FEATURE_SELECTION);
    String[] selectionMethodNames = SELECTION_METHODS.keySet().toArray(new String[SELECTION_METHODS.size()]);
    String selectedMethod = selectionMethodNames[selectionMethodIndex]; // getParameterAsString(PARAMETER_FEATURE_SELECTION);
    Class<? extends LinearRegressionMethod> methodClass = SELECTION_METHODS.get(selectedMethod);
    if (methodClass == null) {
        throw new UserError(this, 904, PARAMETER_FEATURE_SELECTION, "unknown method");
    }
    LinearRegressionMethod method;
    try {
        method = methodClass.newInstance();
    } catch (InstantiationException e) {
        throw new UserError(this, 904, PARAMETER_FEATURE_SELECTION, e.getMessage());
    } catch (IllegalAccessException e) {
        throw new UserError(this, 904, PARAMETER_FEATURE_SELECTION, e.getMessage());
    }

    // apply feature selection technique
    LinearRegressionResult result = method.applyMethod(this, useBias, ridge, exampleSet, isUsedAttribute,
            numberOfExamples, numberOfUsedAttributes, means, labelMean, standardDeviations,
            labelStandardDeviation, coefficientsOnFullData, errorOnFullData);

    // clean up eventually if was classification
    if (cleanUpLabel) {
        exampleSet.getAttributes().remove(workingLabel);
        exampleSet.getExampleTable().removeAttribute(workingLabel);
        exampleSet.getAttributes().setLabel(label);
    }

    // +++++++++++++++++++++++++++++++++++++++++++++
    // calculating statistics of the resulting model
    // +++++++++++++++++++++++++++++++++++++++++++++
    FDistribution fdistribution = new FDistribution(1, exampleSet.size() - result.coefficients.length);
    int length = result.coefficients.length;
    double[] standardErrors = new double[length];
    double[] standardizedCoefficients = new double[length];
    double[] tolerances = new double[length];
    double[] tStatistics = new double[length];
    double[] pValues = new double[length];

    // calculating standard error matrix, (containing the error of
    // intercept)
    double mse = result.error / (exampleSet.size() - 1);

    int finalNumberOfAttributes = 0;
    for (boolean b : result.isUsedAttribute) {
        if (b) {
            finalNumberOfAttributes++;
        }
    }
    double[][] data = new double[exampleSet.size() + 1][finalNumberOfAttributes + 1];
    for (int i = 0; i < data[0].length; i++) {
        data[0][i] = 1;
    }
    for (int i = 0; i < exampleSet.size() + 1; i++) {
        data[i][0] = 1;
    }

    int eIndex = 1;
    for (Example e : exampleSet) {
        int aIndex = 0;
        int aCounter = 1;
        for (Attribute a : exampleSet.getAttributes()) {
            if (result.isUsedAttribute[aIndex]) {
                data[eIndex][aCounter] = e.getValue(a);
                aCounter++;
            }
            aIndex++;
        }
        eIndex++;
    }
    RealMatrix matrix = MatrixUtils.createRealMatrix(data);
    RealMatrix matrixT = matrix.transpose();
    RealMatrix productMatrix = matrixT.multiply(matrix);
    RealMatrix invertedMatrix = null;
    try {
        // try to invert matrix
        invertedMatrix = new LUDecomposition(productMatrix).getSolver().getInverse();

        int index = 0;
        for (int i = 0; i < result.isUsedAttribute.length; i++) {
            if (result.isUsedAttribute[i]) {

                tolerances[index] = getTolerance(exampleSet, result.isUsedAttribute, i, ridge, useBias);
                standardErrors[index] = Math.sqrt(mse * invertedMatrix.getEntry(index + 1, index + 1));
                // calculate standardized Coefficients

                //
                // Be careful, use in the calculation of standardizedCoefficients the i instead
                // of index for
                // standardDeviations, because all other arrays
                // refer to the selected attributes, whereas standardDeviations refers to
                // all attributes
                //
                standardizedCoefficients[index] = result.coefficients[index]
                        * (standardDeviations[i] / labelStandardDeviation);

                if (!Tools.isZero(standardErrors[index])) {
                    tStatistics[index] = result.coefficients[index] / standardErrors[index];
                    double probability = fdistribution
                            .getProbabilityForValue(tStatistics[index] * tStatistics[index]);
                    pValues[index] = probability < 0 ? 1.0d : Math.max(0.0d, 1.0d - probability);
                } else {
                    if (Tools.isZero(result.coefficients[index])) {
                        tStatistics[index] = 0.0d;
                        pValues[index] = 1.0d;
                    } else {
                        tStatistics[index] = Double.POSITIVE_INFINITY;
                        pValues[index] = 0.0d;
                    }
                }
                index++;
            }
        }
    } catch (Throwable e) {

        // calculate approximate value if matrix can not be inverted
        double generalCorrelation = getCorrelation(exampleSet, isUsedAttribute, coefficientsOnFullData,
                useBias);
        generalCorrelation = Math.min(generalCorrelation * generalCorrelation, 1.0d);

        int index = 0;
        for (int i = 0; i < result.isUsedAttribute.length; i++) {
            if (result.isUsedAttribute[i]) {
                // calculating standard error and tolerance
                double tolerance = getTolerance(exampleSet, result.isUsedAttribute, i, ridge, useBias);
                standardErrors[index] = Math
                        .sqrt((1.0d - generalCorrelation)
                                / (tolerance * (exampleSet.size() - exampleSet.getAttributes().size() - 1.0d)))
                        * labelStandardDeviation / standardDeviations[i];
                tolerances[index] = tolerance;

                // calculating beta and test statistics
                // calculate standardized coefficients

                //
                // Be careful, use in the calculation of standardizedCoefficients the i instead
                // of index for
                // standardDeviations, because all other arrays
                // refer to the selected attributes, whereas standardDeviations refers to
                // all attributes
                //
                standardizedCoefficients[index] = result.coefficients[index]
                        * (standardDeviations[i] / labelStandardDeviation);

                if (!Tools.isZero(standardErrors[index])) {
                    tStatistics[index] = result.coefficients[index] / standardErrors[index];
                    double probability = fdistribution
                            .getProbabilityForValue(tStatistics[index] * tStatistics[index]);
                    pValues[index] = probability < 0 ? 1.0d : Math.max(0.0d, 1.0d - probability);
                } else {
                    if (Tools.isZero(result.coefficients[index])) {
                        tStatistics[index] = 0.0d;
                        pValues[index] = 1.0d;
                    } else {
                        tStatistics[index] = Double.POSITIVE_INFINITY;
                        pValues[index] = 0.0d;
                    }
                }
                index++;
            }
        }
    }

    // Set all values for intercept
    if (invertedMatrix == null) {
        standardErrors[standardErrors.length - 1] = Double.POSITIVE_INFINITY;
    } else {
        standardErrors[standardErrors.length - 1] = Math.sqrt(mse * invertedMatrix.getEntry(0, 0));
    }
    tolerances[tolerances.length - 1] = Double.NaN;
    standardizedCoefficients[standardizedCoefficients.length - 1] = Double.NaN;
    if (!Tools.isZero(standardErrors[standardErrors.length - 1])) {
        tStatistics[tStatistics.length - 1] = result.coefficients[result.coefficients.length - 1]
                / standardErrors[standardErrors.length - 1];
        double probability = fdistribution.getProbabilityForValue(
                tStatistics[tStatistics.length - 1] * tStatistics[tStatistics.length - 1]);
        pValues[pValues.length - 1] = probability < 0 ? 1.0d : Math.max(0.0d, 1.0d - probability);
    } else {
        if (Tools.isZero(result.coefficients[result.coefficients.length - 1])) {
            tStatistics[tStatistics.length - 1] = 0.0d;
            pValues[pValues.length - 1] = 1.0d;
        } else {
            tStatistics[tStatistics.length - 1] = Double.POSITIVE_INFINITY;
            pValues[pValues.length - 1] = 0.0d;
        }
    }

    // delivering weights
    if (weightOutput.isConnected()) {
        AttributeWeights weights = new AttributeWeights(exampleSet);
        int selectedAttributes = 0;
        for (int i = 0; i < attributeNames.length; i++) {
            if (isUsedAttribute[i]) {
                weights.setWeight(attributeNames[i], result.coefficients[selectedAttributes]);
                selectedAttributes++;
            } else {
                weights.setWeight(attributeNames[i], 0);
            }
        }
        weightOutput.deliver(weights);
    }

    return new LinearRegressionModel(exampleSet, result.isUsedAttribute, result.coefficients, standardErrors,
            standardizedCoefficients, tolerances, tStatistics, pValues, useBias, firstClassName,
            secondClassName);
}