Bug 428452 - [1.8][clean up][quick assist] Lambdification of AccessController.doPrivileged() produces code that won't compile
Summary: [1.8][clean up][quick assist] Lambdification of AccessController.doPrivileged...
Status: CLOSED DUPLICATE of bug 423439
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-18 11:05 EST by Steve Northover CLA
Modified: 2014-02-18 13:23 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Northover CLA 2014-02-18 11:05:23 EST
Here is a class that contains 3 methods.  The first method is the original, the second is the Eclipse Lambdification of the original, and the third is a possible correct lambdification of the first method.

package junk;

import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;

public class Junk7 {
    private static int readValue(final String name) throws Exception {
        final Class<?> clazz = Junk7.class;
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Integer>() {
                public Integer run() throws Exception {
                    Field field = clazz.getDeclaredField(name);
                    field.setAccessible(true);
                    return field.getInt(clazz);
                }
            });
    }
    
    //BAD - result of bad lamdification by Eclipse (does not compile)
    private static int readValueBAD(final String name) throws Exception {
        final Class<?> clazz = Junk7.class;
        return AccessController.doPrivileged(
            () -> {
                Field field = clazz.getDeclaredField(name);
                field.setAccessible(true);
                return field.getInt(clazz);
            });
    }
    
    //GOOD - this is an example of possible good lambdification
    private static int readValueGOOD(final String name) throws Exception {
        final Class<?> clazz = Junk7.class;
        return AccessController.doPrivileged(
            (PrivilegedExceptionAction<Integer>) () -> {
                Field field = clazz.getDeclaredField(name);
                field.setAccessible(true);
                return field.getInt(clazz);
        });
    }
}
Comment 1 Stephan Herrmann CLA 2014-02-18 11:09:49 EST
To spell out the problem: 

        return AccessController.doPrivileged(
                                ^^^^^^^^^^^^
The method doPrivileged(PrivilegedAction<Integer>) is ambiguous for the type AccessController


Moving to JDT/UI
Comment 3 Noopur Gupta CLA 2014-02-18 13:23:44 EST

*** This bug has been marked as a duplicate of bug 423439 ***