Java Code Examples for java.util.NoSuchElementException#getMessage()

The following examples show how to use java.util.NoSuchElementException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleController.java    From fullstop with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{id}", method = PUT)
@ApiOperation(value = "updates a rule by invalidating it and creating a new rule",
        authorizations = {@Authorization(value = "oauth", scopes = {@AuthorizationScope(scope = "uid", description = "")})})
@ApiResponses(value = {@ApiResponse(code = 200, message = "Updated")})
@ResponseStatus(OK)
public RuleEntity updateWhitelisting(@RequestBody final RuleDTO ruleDTO,
                                     @PathVariable("id") final Long id,
                                     @ApiIgnore @AuthenticationPrincipal(errorOnInvalidType = true) final String userId)
        throws ForbiddenException, NotFoundException {

    checkPermission(userId);

    final RuleEntity ruleEntity;

    try {
        ruleEntity = ruleEntityService.update(ruleDTO, id);
    } catch (final NoSuchElementException e) {
        throw new NotFoundException(e.getMessage());
    }

    return ruleEntity;
}
 
Example 2
Source File: ConfigDiagnostic.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void missingValue(String name, NoSuchElementException ex) {
    final String message = ex.getMessage();
    final String loggedMessage = String.format("Configuration key \"%s\" is required, but its value is empty/missing: %s",
            name,
            message == null ? ex.toString() : message);
    log.error(loggedMessage);
    errorsMessages.add(loggedMessage);
}
 
Example 3
Source File: HookHandler.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
private GitLabHookEventType getEventType(HttpServletRequest req) {
    try {
        return byHeader(req.getHeader(GITLAB_EVENT_TYPE_HEADER));
    } catch (NoSuchElementException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
 
Example 4
Source File: ChangeMapFile.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a map file for output.  If the file exists it will be updated,
 * otherwise a new file will be created.
 * @param file map file
 * @param targetFile associated target buffer file
 * @param create if true a new map file will be created
 * @throws IOException if file already exists or an IO error occurs
 */
ChangeMapFile(File file, LocalManagedBufferFile oldFile, LocalManagedBufferFile newFile) throws IOException {

	this.file = file;
	readOnly = false;
	
	LocalBufferFile mapFile = null;
	boolean success = false;
	try {
		if (!file.exists()) {

			indexCnt = oldFile.getIndexCount();

			bufMgr = new BufferMgr(BufferMgr.DEFAULT_BUFFER_SIZE, CACHE_SIZE, 1);
			bufMgr.setParameter(MAGIC_NUMBER_PARM, MAGIC_NUMBER);
			int ver = oldFile.getVersion();
			bufMgr.setParameter(INITIAL_VERSION_PARM, ver);
			bufMgr.setParameter(INDEX_CNT_PARM, indexCnt);
			
			// Create chained buffer
			int size = ((indexCnt - 1) / 8) + 1;
			buffer = new ChainedBuffer(size, bufMgr);
			bufMgr.setParameter(BUFFER_ID_PARM, buffer.getId());
			
			// Mark all spare bits as changed
			
			
			int lastByteOffset = (indexCnt-1) / 8;
			byte lastByte = 0;
			int index = indexCnt;
			int bit;
			while((bit = index % 8) != 0) {
				int bitMask = 1 << bit;
				lastByte = (byte)(lastByte | bitMask);
				++index;
			}
			buffer.putByte(lastByteOffset, lastByte);
							
		}
		else {

			mapFile = new LocalBufferFile(file, true);
			if (mapFile.getParameter(MAGIC_NUMBER_PARM) != MAGIC_NUMBER) {
				throw new IOException("Bad modification map file: " + file);
			}
			
			long oldTargetFileId = ((long)mapFile.getParameter(TARGET_FILE_ID_HI_PARM) << 32) |
				(mapFile.getParameter(TARGET_FILE_ID_LOW_PARM) & 0xffffffffL);
			if (oldTargetFileId != oldFile.getFileId()) {
				throw new IOException("Modification map file does not correspond to target: " + file);
			}
			
			bufMgr = new BufferMgr(mapFile, CACHE_SIZE, 1);
			
			indexCnt = bufMgr.getParameter(INDEX_CNT_PARM);
			if (newFile.getIndexCount() < indexCnt) {
				throw new AssertException();
			}

			int id = bufMgr.getParameter(BUFFER_ID_PARM);
			buffer = new ChainedBuffer(bufMgr, id);
		}
		
		long targetFileId = newFile.getFileId();
		bufMgr.setParameter(TARGET_FILE_ID_HI_PARM, (int)(targetFileId >> 32));
		bufMgr.setParameter(TARGET_FILE_ID_LOW_PARM, (int)(targetFileId & 0xffffffffL));
		
		success = true;
	}
	catch (NoSuchElementException e) {
		throw new IOException("Required modification map paramater (" + e.getMessage() + ") not found: " + file);
	}
	finally {
		if (!success) {
			if (bufMgr != null) {
				bufMgr.dispose();
			}
			else if (mapFile != null) {
				mapFile.dispose();
			}
		}
	}
}
 
Example 5
Source File: ChangeMapFile.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Construct map file for reading.  
 * @param file existing map file
 * @throws IOException if an IO error occurs
 */
ChangeMapFile(File file, LocalBufferFile targetFile) throws IOException {

	this.file = file;
	readOnly = true;
	
	LocalBufferFile mapFile = null;
	boolean success = false;
	try {
		mapFile = new LocalBufferFile(file, true);
		if (mapFile.getParameter(MAGIC_NUMBER_PARM) != MAGIC_NUMBER) {
			throw new IOException("Bad modification map file: " + file);
		}
		
		long oldTargetFileId = ((long)mapFile.getParameter(TARGET_FILE_ID_HI_PARM) << 32) |
			(mapFile.getParameter(TARGET_FILE_ID_LOW_PARM) & 0xffffffffL);
		if (oldTargetFileId != targetFile.getFileId()) {
			throw new IOException("Modification map file does not correspond to target: " + file);
		}
	
		bufMgr = new BufferMgr(mapFile, CACHE_SIZE, 1);
		
		indexCnt = bufMgr.getParameter(INDEX_CNT_PARM);
		if (targetFile.getIndexCount() < indexCnt) {
			throw new AssertException();
		}
		
		int id = bufMgr.getParameter(BUFFER_ID_PARM);
		buffer = new ChainedBuffer(bufMgr, id);
		success = true;
	}
	catch (NoSuchElementException e) {
		throw new IOException("Required modification map paramater (" + e.getMessage() + ") not found: " + file);
	}
	finally {
		if (!success) {
			if (bufMgr != null) {
				bufMgr.dispose();
			}
			else if (mapFile != null) {
				mapFile.dispose();
			}
		}
	}
}
 
Example 6
Source File: RepositoryService.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
/**
 * Wrapper for {@link Repository#findRepositoryItemById(String)} that throws a checked exception
 * when the item is not found.
 *
 * @param itemId
 *          the id of a repository item
 * @return the found object
 * @throws ItemNotFoundException
 *           when there's no instance with the provided id
 */
private RepositoryItem findRepositoryItemById(String itemId) throws ItemNotFoundException {
  try {
    return repository.findRepositoryItemById(itemId);
  } catch (NoSuchElementException e) {
    log.debug("Provided id is not valid", e);
    throw new ItemNotFoundException(e.getMessage());
  }
}