Bug 69895

Summary: [1.5] GenericList.getLast() should flag error if not in try block/
Product: [Eclipse Project] JDT Reporter: Michael Schneider <michaelschneider>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: 3.1 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Michael Schneider CLA 2004-07-13 00:41:53 EDT
I am using a generic linked list


GenericList.getLast();

should be an error if not in try block, or in function that
with a throw statement.

1) No Error
2) No Quick Fix

Thanks
Mike
Comment 1 Philipe Mulet CLA 2004-07-14 06:17:44 EDT
LinkedList.getLast() doesn't declare any exception.
Comment 2 Michael Schneider CLA 2004-07-14 09:03:51 EDT
Here is the code for getLast from Java 1.5 beta 2.

Thanks
Mike


    /**
     * Returns the last element in this list.
     *
     * @return the last element in this list.
     * @throws    NoSuchElementException if this list is empty.
     */
    public E getLast()  {
	if (size==0)
	    throw new NoSuchElementException();

	return header.previous.element;
    }
Comment 3 Michael Schneider CLA 2004-07-14 09:09:17 EDT
---- FYI ---- here is the code from java 1.4


    /**
     * Returns the last element in this list.
     *
     * @return the last element in this list.
     * @throws    NoSuchElementException if this list is empty.
     */
    public Object getLast()  {
	if (size==0)
	    throw new NoSuchElementException();

	return header.previous.element;
    }

-------------------------------------------------
Comment 4 Philipe Mulet CLA 2004-07-14 09:49:32 EDT
This is what I said earlier, it does not declare any exception; thus can only 
throw unchecked exception which a compiler is not reporting. 
This is described in language specs.