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

The following examples show how to use java.util.NoSuchElementException#initCause() . 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: ResultSetIterator.java    From requery with Apache License 2.0 6 votes vote down vote up
@Override
public E next() {
    if (closed) {
        throw new IllegalStateException();
    }
    try {
        if (!advanced) {
            // move forward
            if (!results.next()) {
                advanced = false;
                close();
                throw new NoSuchElementException();
            }
        } // else already ready to read
        E value = reader.read(results, selection);
        position++;
        advanced = false;
        return value;
    } catch (SQLException e) {
        NoSuchElementException exception = new NoSuchElementException();
        exception.initCause(e);
        throw exception;
    }
}
 
Example 2
Source File: PageIterator.java    From java-asana with MIT License 6 votes vote down vote up
@Override
public Collection<T> next() throws NoSuchElementException {
    if (!hasNext()) {
        throw new NoSuchElementException("No more pages through Asana API.");
    } else if (ioException != null) {
        // Wrapping an IOException in a NoSuchElementException is questionable practice, but the API has been this
        // way since commit 23f13ec from 2015-04-03, so we leave the type for API backwards compatibility.
        NoSuchElementException newException
            = new NoSuchElementException("IOException when communicating through Asana API.");
        newException.initCause(ioException);
        throw newException;
    }

    Collection<T> currentData = nextData;
    nextData = null;
    return currentData;
}
 
Example 3
Source File: LazySegmentedIterator.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Indicates if the iterator has another element.
 */
@Override
@DoesServiceRequest
public boolean hasNext() {
    while (this.currentSegment == null
            || (!this.currentSegmentIterator.hasNext() && this.currentSegment != null && this.currentSegment
                    .getHasMoreResults())) {
        try {
            this.currentSegment = ExecutionEngine.executeWithRetry(this.client, this.parentObject,
                    this.segmentGenerator, this.policyFactory, this.opContext);
        }
        catch (final StorageException e) {
            final NoSuchElementException ex = new NoSuchElementException(SR.ENUMERATION_ERROR);
            ex.initCause(e);
            throw ex;
        }
        this.currentSegmentIterator = this.currentSegment.getResults().iterator();

        if (!this.currentSegmentIterator.hasNext() && !this.currentSegment.getHasMoreResults()) {
            return false;
        }
    }

    return this.currentSegmentIterator.hasNext();
}
 
Example 4
Source File: XMLEventReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 5
Source File: XMLEventReaderImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 6
Source File: XMLEventReaderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 7
Source File: XMLEventReaderImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 8
Source File: XMLEventReaderImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 9
Source File: XMLEventReaderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 10
Source File: XMLEventReaderImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 11
Source File: XMLEventReaderImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 12
Source File: XMLEventReaderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 13
Source File: CredentialFactory.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected void getCredentialsFromAlias() {
	if (!gotCredentials && StringUtils.isNotEmpty(getAlias())) {
		try {
			Set principals = new HashSet();
			Set publicCredentials = new HashSet();
			Set privateCredentials = new HashSet();
			Principal p = new IbisPrincipal();
			principals.add(p);
			Subject initialSubject= new Subject(false,principals,publicCredentials,privateCredentials);
			String loginConfiguration = AppConstants.getInstance().getProperty("PrincipalMapping","DefaultPrincipalMapping");
			LoginContext lc = new LoginContext(loginConfiguration, initialSubject, this);
			lc.login();
			Subject s = lc.getSubject();
			//showSet(s.getPrincipals(),"principals");
			//showSet(s.getPublicCredentials(),"PublicCredentials");
			//showSet(s.getPrivateCredentials(),"PrivateCredentials");
			//Object pwcred=Subject.doAsPrivileged(s,new PasswordGetter(s),AccessController.getContext());
			//Object pwcred=AccessController.doPrivileged(new PasswordGetter(s));
			
			Object pwcred = s.getPrivateCredentials().toArray()[0];

			setUsername(ClassUtils.invokeStringGetter(pwcred,"getUserName"));
			setPassword(invokeCharArrayGetter(pwcred,"getPassword"));
			gotCredentials=true;
		} catch (Exception e) {
			if (!useFallback) {
				NoSuchElementException nsee=new NoSuchElementException("cannot obtain credentials from authentication alias ["+getAlias()+"]"); 
				nsee.initCause(e);
				throw nsee;
			}
			log.error("exception obtaining credentials for alias ["+getAlias()+"]",e);

			String usernameProp="alias."+getAlias()+".username";
			String passwordProp="alias."+getAlias()+".password";
			log.info("trying to solve Authentication Alias from application properties ["+usernameProp+"] and ["+passwordProp+"]");
			setUsername(AppConstants.getInstance().getProperty(usernameProp,username));
			setPassword(AppConstants.getInstance().getProperty(passwordProp,password));
		}
	}
}