Example usage for java.lang ExceptionInInitializerError ExceptionInInitializerError

List of usage examples for java.lang ExceptionInInitializerError ExceptionInInitializerError

Introduction

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

Prototype

public ExceptionInInitializerError(String s) 

Source Link

Document

Constructs an ExceptionInInitializerError with the specified detail message string.

Usage

From source file:io.valuesfeng.picker.Picker.java

public static Picker from(Fragment fragment) {
    if (hasInitPicker)
        throw new ExceptionInInitializerError(INITIALIZE_PICKER_ERROR);
    hasInitPicker = true;/*  www  .  ja v a  2s . com*/
    return new Picker(fragment.getActivity(), fragment);
}

From source file:org.viafirma.cliente.ViafirmaClientFactory.java

/**
 * Retorna una instancia del cliente de firma
 * //from w  ww. ja v a 2s . co m
 * @return
 */
public static ViafirmaClient getInstance() {
    if (singleton == null) {
        throw new ExceptionInInitializerError("El Cliente no ha sido inicializado");
    }
    return singleton;
}

From source file:com.opentable.db.postgres.embedded.BundledPostgresBinaryResolver.java

public File prepareBinaries(final String system, final String machineHardware,
        final Optional<File> targetPath) {
    PREPARE_BINARIES_LOCK.lock();/*from   ww w  .jav a 2s  .c  o m*/
    try {

        LOG.info("Detected a {} {} system", system, machineHardware);
        File pgDir;
        final File pgBundle = getPgBundle(this.pgVersion, system, machineHardware);

        if (pgBundle == null) {
            throw new IllegalStateException("No Postgres binary found for " + system + " / " + machineHardware);
        }

        if (targetPath.isPresent()) {
            pgDir = targetPath.get();
        } else {
            pgDir = new File(TMP_DIR, String.format("PG-%s", pgVersion));
        }

        mkdirs(pgDir);
        final File unpackLockFile = new File(pgDir, LOCK_FILE_NAME);
        final File pgDirExists = new File(pgDir, ".exists");

        if (!pgDirExists.exists()) {
            try (final FileOutputStream lockStream = new FileOutputStream(unpackLockFile);
                    final FileLock unpackLock = lockStream.getChannel().tryLock()) {
                if (unpackLock != null) {
                    try {
                        Preconditions.checkState(!pgDirExists.exists(),
                                "unpack lock acquired but .exists file is present.");
                        LOG.info("Extracting Postgres...");
                        extractTxz(pgBundle.getPath(), pgDir.getPath());
                        Verify.verify(pgDirExists.createNewFile(), "couldn't make .exists file");
                    } catch (Exception e) {
                        LOG.error("while unpacking Postgres", e);
                        throw e;
                    }
                } else {
                    // the other guy is unpacking for us.
                    int maxAttempts = 60;
                    while (!pgDirExists.exists() && --maxAttempts > 0) {
                        Thread.sleep(1000L);
                    }
                    Verify.verify(pgDirExists.exists(),
                            "Waited 60 seconds for postgres to be unpacked but it never finished!");
                }
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
                throw new ExceptionInInitializerError(ie);
            } catch (IOException e) {
                throw new ExceptionInInitializerError(e);
            } finally {
                if (unpackLockFile.exists()) {
                    Verify.verify(unpackLockFile.delete(), "could not remove lock file %s",
                            unpackLockFile.getAbsolutePath());
                }
            }
        }
        LOG.info("Postgres binaries at {}", pgDir);
        return pgDir;
    } finally {
        PREPARE_BINARIES_LOCK.unlock();
    }
}

From source file:io.valuesfeng.picker.Picker.java

public static Picker from(Fragment fragment, Set<MimeType> mimeType) {
    if (hasInitPicker)
        throw new ExceptionInInitializerError(INITIALIZE_PICKER_ERROR);
    hasInitPicker = true;/*  w  ww . j av  a2s . c o m*/
    return new Picker(fragment.getActivity(), fragment, mimeType);
}

From source file:com.ning.http.client.providers.apache.TestableApacheAsyncHttpProvider.java

/**
 * Because COPY-PASTE-MODIFY is such a terribly bad design decision, we at least need to ensure
 * that the copy-paste-modified class still corresponds to the same implementing class. Therefore,
 * we calculate a few checksums to make sure that this class' parent has the same bytecode as the
 * one it was written against./*from  w  w  w  .  j  a v a  2s. c  om*/
 */
private static void verifyMyCorrespondingClassHasNotChanged() {
    ChecksumClassFile checksum = new ChecksumClassFile();
    Class<?> clazz = ApacheAsyncHttpProvider.class;

    String md5, sha;
    try {
        md5 = checksum.md5(clazz);
        sha = checksum.sha(clazz);
    } catch (CannotCompileException | NoSuchAlgorithmException | NotFoundException | IOException e) {
        throw new ExceptionInInitializerError(e);
    }

    if (!md5.equals("PrXXU6W0YOncEoAdb/sbqA=="))
        throw new ExceptionInInitializerError(
                "Invalid checksum. The test using this class is no longer valid because "
                        + ApacheAsyncHttpProvider.class.getName() + " has changed.");
    if (!sha.equals("fo9e70O9IDEJl0y2g+6DDqnipYY="))
        throw new ExceptionInInitializerError(
                "Invalid checksum. The test using this class is no longer valid because "
                        + ApacheAsyncHttpProvider.class.getName() + " has changed.");
}

From source file:org.alfresco.repo.web.util.AbstractJettyComponent.java

protected void configure(WebAppContext webAppContext) {
    try {/*  w  ww.  j a v a2 s  . c om*/
        ClassLoader classLoader = BaseApplicationContextHelper.buildClassLoader(classLocations);
        webAppContext.setClassLoader(classLoader);
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }

    webAppContext.addEventListener(new ServletContextListener() {
        public void contextInitialized(ServletContextEvent sce) {
            // create a Spring web application context, wrapping and providing access to
            // the application context
            try {
                ServletContext servletContext = sce.getServletContext();

                // initialise web application context
                WebApplicationContextLoader.getApplicationContext(servletContext, configLocations,
                        classLocations);

                if (logger.isDebugEnabled()) {
                    logger.debug("contextInitialized " + sce);
                }
            } catch (Throwable t) {
                logger.error("Failed to start Jetty server: " + t);
                throw new AlfrescoRuntimeException("Failed to start Jetty server", t);
            }
        }

        public void contextDestroyed(ServletContextEvent sce) {
            if (logger.isDebugEnabled()) {
                logger.debug("contextDestroyed " + sce);
            }
        }
    });

    // with a login-config in web.xml, jetty seems to require this in order to start successfully
    webAppContext.getSecurityHandler().setLoginService(new HashLoginService());

    // arbitrary temporary file location
    File tmp = new File(TempFileProvider.getSystemTempDir(), String.valueOf(System.currentTimeMillis()));
    webAppContext.setResourceBase(tmp.getAbsolutePath());
}

From source file:org.webical.manager.impl.EventManagerImpl.java

public void afterPropertiesSet() throws Exception {
    if (daoFactory == null) {
        throw new ExceptionInInitializerError(EVENT_MANAGER_IMPL_NEEDS_DAO_FACTORY);
    }/*  w  w  w .  j a v  a  2 s  . c o  m*/

    if (log.isDebugEnabled()) {
        log.debug("Class of UserDao set by Spring: " + daoFactory.getClass());
    }
}

From source file:edu.usc.goffish.gopher.impl.client.GopherClient.java

/**
 * Sent initial data required by the application
 *
 * @param message SubGraph message which contains the data
 * @throws NullPointerException if message is null for data is empty
 *///from w  w w  .j  a v a 2  s.  c  o  m
public void sendData(SubGraphMessage message) throws NullPointerException {

    if (message == null) {
        throw new NullPointerException("Invalid arguments : message is null ");
    }

    if (message.getData() == null) {
        throw new NullPointerException("Message with empty data");
    }

    if (sender == null) {
        String msg = "Gopher client is not initialized properly";
        handleException(msg, new ExceptionInInitializerError(msg));
    }

    BSPMessage frameworkMsg = new BSPMessage();
    frameworkMsg.setType(BSPMessage.DATA);
    frameworkMsg.setData(BitConverter.getBytes(message));

    Message tempMessage = new MessageImpl();
    tempMessage.putPayload(BitConverter.getBytes(frameworkMsg));

    sender.send(tempMessage);

}

From source file:dk.netarkivet.common.distribute.arcrepository.BitarchiveRecord.java

/**
 * Creates a BitarchiveRecord from the a ArchiveRecord, which can be either
 * a ARCRecord or WARCRecord. Note that record metadata is not included with
 * the BitarchiveRecord, only the payload of the record.
 * //  ww  w . jav  a2  s . c o  m
 * If the length of the record is higher than Settings
 * .BITARCHIVE_LIMIT_FOR_RECORD_DATATRANSFER_IN_FILE
 *  the data is stored in a RemoteFile, otherwise the data is stored in
 *  a byte array.
 * @param record the ArchiveRecord that the data should come from.  We do not
 * close the ArchiveRecord.
 * @param filename The filename of the ArchiveFile
*/
public BitarchiveRecord(ArchiveRecord record, String filename) {
    ArgumentNotValid.checkNotNull(record, "ArchiveRecord record");
    ArgumentNotValid.checkNotNull(filename, "String filename");
    this.fileName = filename;
    this.offset = record.getHeader().getOffset();
    if (record instanceof ARCRecord) {
        length = record.getHeader().getLength();
    } else if (record instanceof WARCRecord) {
        // The length of the payload of the warc-record is not getLength(),
        // but getLength minus getContentBegin(), which is the number of
        // bytes used for the record-header!
        length = record.getHeader().getLength() - record.getHeader().getContentBegin();
    } else {
        throw new ArgumentNotValid("Unknown type of ArchiveRecord");
    }
    if (length > LIMIT_FOR_SAVING_DATA_IN_OBJECT_BUFFER) {
        // copy arc-data to local file and create a RemoteFile based on this
        log.info("Record exceeds limit of " + LIMIT_FOR_SAVING_DATA_IN_OBJECT_BUFFER + " bytes. Length is "
                + length + " bytes, Storing as instance of " + Settings.get(CommonSettings.REMOTE_FILE_CLASS));
        if (RemoteFileFactory.isExtendedRemoteFile()) {
            objectAsRemoteFile = RemoteFileFactory.getExtendedInstance(record);
            isStoredAsRemoteFile = true;
        } else {
            File localTmpFile = null;
            try {
                localTmpFile = File.createTempFile("BitarchiveRecord-" + fileName, ".tmp",
                        FileUtils.getTempDir());
                record.dump(new FileOutputStream(localTmpFile));
                objectAsRemoteFile = RemoteFileFactory.getMovefileInstance(localTmpFile);
                isStoredAsRemoteFile = true;
            } catch (IOException e) {
                throw new IOFailure("Unable to store record(" + fileName + "," + offset + ") as remotefile", e);
            }
        }
    } else { // Store data in objectbuffer
        try {
            if (record instanceof ARCRecord) {
                objectBuffer = ARCUtils.readARCRecord((ARCRecord) record);
            } else if (record instanceof WARCRecord) {
                objectBuffer = WARCUtils.readWARCRecord((WARCRecord) record);
            }
            log.debug("Bytes stored in objectBuffer: " + objectBuffer.length);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }
}

From source file:org.viafirma.cliente.util.ConfigUtil.java

/**
 * Inicializa el filtro. /*from   ww  w.j  a  v  a2s  .c  om*/
 * Configura el cliente Viafirma.
 */
public void init(FilterConfig config) {
    if (!isInit) {
        isInit = true;
        // recuperamos la configuracin del contexto
        /*
         *       <!--  Configuracin del cliente de ejemplo integrado en la plataforma -->
        <Environment description="Configuracin del Cliente:Proveedor OpenID utilizado para la autenticacin"
                 name="URL_DEFAULT_AUTHENTICATION_PROVIDER"
                 value="http://localhost:8080/viafirma/pip/#ID#" type="java.lang.String" override="false"/>
        <Environment description="Configuracin del Cliente:Proveedor OpenID utilizado para la firma de documentos"
                 name="URL_DEFAULT_SIGN_PROVIDER"
                 value="http://localhost:8080/viafirma/sign/#ID#" type="java.lang.String" override="false"/>
        <Environment description="Configuracin del Cliente: Url de retorno de los datos usdado por el cliente. Es la url que informa el cliente al servidor para que este le retorne aqui el resultado"
                 name="URL_AUTHENTICATION_RETURN_OPEN_ID"
                 value="http://localhost:8080/viafirma/testAuthentication" type="java.lang.String" override="false"/>
        <Environment description="Configuracin del Cliente: Url de retorno del resultado de la firma usdado por el cliente. Es la url que informa el cliente al servidor para que este le retorne aqui el resultado"
                 name="URL_FIRMA_RETURN_OPEN_ID"
                 value="http://localhost:8080/viafirma/testFirma" type="java.lang.String" override="false"/>
                
         * 
         */

        // recuperamos la url en la que se encuentra el proveedor de Viafirma que se desea utilizar
        Properties properties = ConfigUtil.getInstance().readConfigPropertes();
        // las propiedades que esperamos recuperar son: url_proveedor
        String urlProveedor = properties.getProperty(Constantes.PARAM_URL_PROVIDER_VIAFIRMA);
        if (urlProveedor == null) {
            log.error("Falta el prarametro de configuracin :  " + Constantes.PARAM_URL_PROVIDER_VIAFIRMA
                    + ", se intentaran recuperar los parametros de configuracin de forma independiente");
            throw new ExceptionInInitializerError("Parametro '" + Constantes.PARAM_URL_PROVIDER_VIAFIRMA
                    + "' requerido para inicializar el cliente Viafirma.");
        } else {
            // Utilizando el proveedor contruimos las urls de configuracin que necesitamos.
            properties.setProperty(Constantes.PARAM_URL_DEFAULT_AUTHENTICATION_PROVIDER,
                    urlProveedor + "/pip/#ID#");
            properties.setProperty(Constantes.PARAM_URL_DEFAULT_SIGN_PROVIDER, urlProveedor + "/sign/#ID#");
            properties.setProperty(Constantes.PARAM_URL_DEFAULT_SIGN_PROVIDER, urlProveedor + "/sign/#ID#");
        }

        // recupero la url de retorno en caso de error.
        uriError = config.getInitParameter(Constantes.PARAM_URI_ERROR);

        // Inicializamos el cliente Viafirma
        ViafirmaClientFactory.init(properties);
    }

}