List of usage examples for java.lang IllegalArgumentException getCause
public synchronized Throwable getCause()
From source file:org.shaf.shell.Shell.java
/** * Handles the specified shell request.//from w w w.jav a 2 s .c om * * @param request * the shell request. * @return {@code 0} if request executed successfully and {@code 1} * otherwise. */ public int handle(final ShellRequest request) { String cmd = Strings.isNullOrEmpty(request.getCommand()) ? "" : request.getCommand(); String[] args = (request.getArguments() == null) ? new String[0] : request.getArguments(); try { this.fireCommandStarted(request); /* * Creates an action instance based on the specified command and * initiates it execution. */ if (this.actions.contains(cmd)) { LOG.debug("Executes '" + cmd + "' command."); Action action = this.actions.get(cmd).newInstance(); try { if (args.length == 1 && "-?".equals(args[0])) { terminal.print(action.usage()); LOG.debug("Execution successful."); return 0; } else { action.perform(new ActionContext(this.actions, this.config, this.terminal), args); LOG.debug("Execution successful."); return 0; } } catch (IllegalArgumentException exc) { terminal.print("Error:", "\tInvalid command arguments: " + exc.getMessage()); terminal.print(action.usage()); } } else { terminal.println("Unknown command: " + cmd); } } catch (Throwable exc) { terminal.print("Execution failed: " + exc.getMessage(), "", "NOTE: To see the full information about occured error, please, check the ", " Shell log.", ""); LOG.fatal("Execution failed.", exc); if (exc instanceof ClientException) { if (exc.getCause() instanceof NetworkContentException) { LOG.fatal("The faulty content: " + ((NetworkContentException) exc.getCause()).getContent()); } else if (exc.getCause() instanceof NetworkTransportException) { LOG.fatal( "The faulty transport: " + ((NetworkTransportException) exc.getCause()).getTransport()); } } } finally { fireCommandFinished(request); } return 1; }
From source file:com.sworddance.beans.PropertyAdaptor.java
/** * Reads the property of the target object. * * @param target the object to read a property from * @return property's value/*from w ww . ja v a 2 s . c o m*/ */ public Object read(Object target) { if (getter == null) { throw new ApplicationGeneralException("no get" + propertyName + "()"); } else if (target == null) { throw new ApplicationNullPointerException("target to read property " + propertyName + " from is null"); } else { try { return getter.invoke(target); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(getter.toGenericString() + " is not allowed to be called on an object of type =" + target.getClass(), e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(getter.toGenericString() + " (private/protected method?) is not allowed to be called on an object of type =" + target.getClass(), e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(getter.toGenericString() + " target is a " + target.getClass(), e.getCause()); } } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.ApplicationMasterService.java
@Override public RegisterApplicationMasterResponse registerApplicationMaster(RegisterApplicationMasterRequest request) throws YarnException, IOException { AMRMTokenIdentifier amrmTokenIdentifier = YarnServerSecurityUtils.authorizeRequest(); ApplicationAttemptId applicationAttemptId = amrmTokenIdentifier.getApplicationAttemptId(); ApplicationId appID = applicationAttemptId.getApplicationId(); AllocateResponseLock lock = responseMap.get(applicationAttemptId); if (lock == null) { RMAuditLogger.logFailure(amrmTokenIdentifier.getUser().getUserName(), AuditConstants.REGISTER_AM, "Application doesn't exist in cache " + applicationAttemptId, "ApplicationMasterService", "Error in registering application master", appID, applicationAttemptId); throwApplicationDoesNotExistInCacheException(applicationAttemptId); }//from w w w. j a v a 2 s.c o m // Allow only one thread in AM to do registerApp at a time. synchronized (lock) { AllocateResponse lastResponse = lock.getAllocateResponse(); if (hasApplicationMasterRegistered(applicationAttemptId)) { String message = "Application Master is already registered : " + appID; LOG.warn(message); RMAuditLogger.logFailure(this.rmContext.getRMApps().get(appID).getUser(), AuditConstants.REGISTER_AM, "", "ApplicationMasterService", message, appID, applicationAttemptId); throw new InvalidApplicationMasterRequestException(message); } this.amLivelinessMonitor.receivedPing(applicationAttemptId); RMApp app = this.rmContext.getRMApps().get(appID); // Setting the response id to 0 to identify if the // application master is register for the respective attemptid lastResponse.setResponseId(0); lock.setAllocateResponse(lastResponse); LOG.info("AM registration " + applicationAttemptId); this.rmContext.getDispatcher().getEventHandler().handle(new RMAppAttemptRegistrationEvent( applicationAttemptId, request.getHost(), request.getRpcPort(), request.getTrackingUrl())); RMAuditLogger.logSuccess(app.getUser(), AuditConstants.REGISTER_AM, "ApplicationMasterService", appID, applicationAttemptId); // Pick up min/max resource from scheduler... RegisterApplicationMasterResponse response = recordFactory .newRecordInstance(RegisterApplicationMasterResponse.class); response.setMaximumResourceCapability(rScheduler.getMaximumResourceCapability(app.getQueue())); response.setApplicationACLs(app.getRMAppAttempt(applicationAttemptId).getSubmissionContext() .getAMContainerSpec().getApplicationACLs()); response.setQueue(app.getQueue()); if (UserGroupInformation.isSecurityEnabled()) { LOG.info("Setting client token master key"); response.setClientToAMTokenMasterKey(java.nio.ByteBuffer.wrap(rmContext .getClientToAMTokenSecretManager().getMasterKey(applicationAttemptId).getEncoded())); } // For work-preserving AM restart, retrieve previous attempts' containers // and corresponding NM tokens. if (app.getApplicationSubmissionContext().getKeepContainersAcrossApplicationAttempts()) { List<Container> transferredContainers = rScheduler.getTransferredContainers(applicationAttemptId); if (!transferredContainers.isEmpty()) { response.setContainersFromPreviousAttempts(transferredContainers); List<NMToken> nmTokens = new ArrayList<NMToken>(); for (Container container : transferredContainers) { try { NMToken token = rmContext.getNMTokenSecretManager().createAndGetNMToken(app.getUser(), applicationAttemptId, container); if (null != token) { nmTokens.add(token); } } catch (IllegalArgumentException e) { // if it's a DNS issue, throw UnknowHostException directly and // that // will be automatically retried by RMProxy in RPC layer. if (e.getCause() instanceof UnknownHostException) { throw (UnknownHostException) e.getCause(); } } } response.setNMTokensFromPreviousAttempts(nmTokens); LOG.info("Application " + appID + " retrieved " + transferredContainers.size() + " containers from previous" + " attempts and " + nmTokens.size() + " NM tokens."); } } response.setSchedulerResourceTypes(rScheduler.getSchedulingResourceTypes()); return response; } }
From source file:jp.terasoluna.fw.validation.FieldChecksTest11.java
/** * testValidateMultiField05() <br> * <br>// w w w.ja v a 2 s. c o m * () <br> * F, G, I <br> * <br> * () bean:"bean"<br> * () va:ValidatorActionn?<br> * () field:???Field?<br> * <br> * varmultiFieldValidator="java.lang.String"<br> * () errors:MockValidationErrors?<br> * <br> * () errors:errorMessage?null??????<br> * () :IllegalArgumentException<br> * "var value[multiFieldValidator] is invalid."<br> * ??ClassCastException<br> * () :ERROR<br> * "var value[multiFieldValidator] is invalid."<br> * ??ClassCastException<br> * <br> * field??var-namemultiFieldValidator??var-value? MultiFieldValidator?????????????? * IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testValidateMultiField05() throws Exception { // ?? Object bean = "bean"; ValidatorAction va = new ValidatorAction(); Field field = new Field(); Var var = new Var("multiFieldValidator", "java.lang.String", null); field.addVar(var); FieldChecks_ValidationErrorsImpl03 errors = new FieldChecks_ValidationErrorsImpl03(); // FieldChecks fieldChecks = new FieldChecks(); try { fieldChecks.validateMultiField(bean, va, field, errors); fail("IllegalArgumentException??????"); } catch (IllegalArgumentException e) { // assertNull(errors.errorMessage); assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("var value[multiFieldValidator] is invalid.", e.getMessage()); assertTrue(e.getCause() instanceof ClassCastException); assertThat(logger.getLoggingEvents().get(0).getMessage(), is(equalTo("var value[multiFieldValidator] is invalid."))); assertThat(logger.getLoggingEvents().get(0).getThrowable().get(), instanceOf(ClassCastException.class)); } }
From source file:jp.terasoluna.fw.validation.FieldChecksTest11.java
/** * testValidateMultiField04() <br> * <br>// www . j a va 2 s.c o m * () <br> * F, G, I <br> * <br> * () bean:"bean"<br> * () va:ValidatorActionn?<br> * () field:???Field?<br> * <br> * varmultiFieldValidator="not.Exist"<br> * () errors:MockValidationErrors?<br> * <br> * () errors:errorMessage?null??????<br> * () :IllegalArgumentException<br> * "var value[multiFieldValidator] is invalid."<br> * ??ClassLoadException<br> * () :ERROR<br> * "var value[multiFieldValidator] is invalid."<br> * ??ClassLoadException<br> * <br> * field??var-namemultiFieldValidator??var-value?? ????????????IllegalArgumentException? * ????? <br> * @throws Exception ????? */ @Test public void testValidateMultiField04() throws Exception { // ?? Object bean = "bean"; ValidatorAction va = new ValidatorAction(); Field field = new Field(); Var var = new Var("multiFieldValidator", "not.Exist", null); field.addVar(var); FieldChecks_ValidationErrorsImpl03 errors = new FieldChecks_ValidationErrorsImpl03(); // FieldChecks fieldChecks = new FieldChecks(); try { fieldChecks.validateMultiField(bean, va, field, errors); fail("IllegalArgumentException??????"); } catch (IllegalArgumentException e) { // assertNull(errors.errorMessage); assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("var value[multiFieldValidator] is invalid.", e.getMessage()); assertTrue(e.getCause() instanceof ClassLoadException); assertThat(logger.getLoggingEvents().get(0).getMessage(), is(equalTo("var value[multiFieldValidator] is invalid."))); // assertTrue(LogUTUtil.checkError( // "var value[multiFieldValidator] is invalid.", // new ClassLoadException(new RuntimeException()))); assertThat(logger.getLoggingEvents().get(0).getThrowable().get(), instanceOf(ClassLoadException.class)); assertThat(logger.getLoggingEvents().get(0).getThrowable().get().getCause(), instanceOf(ClassNotFoundException.class)); } }
From source file:com.yahoo.pulsar.broker.service.BrokerService.java
public CompletableFuture<Topic> getTopic(final String topic) { try {//from w w w.j a v a 2 s . c o m CompletableFuture<Topic> topicFuture = topics.get(topic); if (topicFuture != null) { return topicFuture; } return topics.computeIfAbsent(topic, this::createPersistentTopic); } catch (IllegalArgumentException e) { log.warn("[{}] Illegalargument exception when loading topic", topic, e); return failedFuture(e); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof ServiceUnitNotReadyException) { log.warn("[{}] Service unit is not ready when loading the topic", topic); } else { log.warn("[{}] Unexpected exception when loading topic: {}", topic, cause); } return failedFuture(cause); } }
From source file:com.flipzu.flipzu.Recorder.java
@Override protected void onPause() { super.onPause(); debug.logV(TAG, "onPause()"); /* unregister status updater */ try {/*from w ww . ja v a 2 s . co m*/ unregisterReceiver(broadcastReceiver); } catch (IllegalArgumentException e) { debug.logE(TAG, "onPause ERROR", e.getCause()); } /* stop timer */ clockHandler.removeCallbacks(mUpdateDurationTask); /* stop comments/listeners */ mHandler.removeCallbacks(mUpdateTimeTask); }
From source file:nl.mpi.lamus.workspace.exporting.implementation.GeneralNodeExporterTest.java
@Test public void exportNullWorkspace() throws MalformedURLException, URISyntaxException, WorkspaceExportException { final String metadataExtension = "cmdi"; final String parentCorpusNamePathToClosestTopNode = ""; // top node final int nodeWsID = 10; final String nodeName = "SomeNode"; final String nodeFilename = nodeName + FilenameUtils.EXTENSION_SEPARATOR_STR + metadataExtension; final URI nodeArchiveURI = new URI(UUID.randomUUID().toString()); final URL nodeArchiveURL = new URL("http:/archive/location/TopNode/Corpusstructure/" + nodeFilename); final boolean keepUnlinkedFiles = Boolean.FALSE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.SUBMIT_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.TREE_EXPORT; workspace.setTopNodeID(nodeWsID);//from w w w .ja v a 2 s .com workspace.setTopNodeArchiveURI(nodeArchiveURI); workspace.setTopNodeArchiveURL(nodeArchiveURL); try { generalNodeExporter.exportNode(null, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "Workspace not set"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.exporting.implementation.GeneralNodeExporterTest.java
@Test public void export_ExportPhaseUnlinkedNodes() throws WorkspaceExportException { final boolean keepUnlinkedFiles = Boolean.TRUE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.SUBMIT_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.UNLINKED_NODES_EXPORT; final String parentCorpusNamePathToClosestTopNode = ""; // top node try {// ww w . ja va 2 s. c om generalNodeExporter.exportNode(workspace, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "This exporter should only be used when exporting the tree, not for unlinked nodes"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }
From source file:nl.mpi.lamus.workspace.exporting.implementation.GeneralNodeExporterTest.java
@Test public void export_SubmissionTypeDelete() throws WorkspaceExportException { final boolean keepUnlinkedFiles = Boolean.TRUE; //not used in this exporter final WorkspaceSubmissionType submissionType = WorkspaceSubmissionType.DELETE_WORKSPACE; final WorkspaceExportPhase exportPhase = WorkspaceExportPhase.UNLINKED_NODES_EXPORT; final String parentCorpusNamePathToClosestTopNode = ""; // top node try {//from www .j a v a 2 s. c o m generalNodeExporter.exportNode(workspace, mockParentWsNode, parentCorpusNamePathToClosestTopNode, mockChildWsNode, keepUnlinkedFiles, submissionType, exportPhase); fail("should have thrown exception"); } catch (IllegalArgumentException ex) { String errorMessage = "This exporter should only be used when submitting the workspace, not when deleting"; assertEquals("Message different from expected", errorMessage, ex.getMessage()); assertNull("Cause should be null", ex.getCause()); } }