Javac bug with lower bounded wildcard?

Hi all,
I have found the below code snippet not to compile with javac (1.5 & 1.6) even though
I think that it is correct. Also the Eclipse Java compiler accepts this code without errors.
Can anyone confirm that this is a bug in javac or maybe explain why the code is really wrong as javac is claiming?
Thanks a lot for any help!
$$$ cat A.java
interface I { }
class C1 { }
class C2 extends C1 implements I { }
public class A<T extends C1 & I> {
A<? super C2> a;
$$$ javac A.java
A.java:6: type parameter ? super C2 is not within its bound
A<? super C2> a;
^
1 error

Hi Danny,
thanks for your feedback. Actually, "? super C2" does not allow any arbitrary supertype of C2 since each type argument must also respect the bounds of the type parameter. Therefore, "? super C2" represents all supertypes of C2 which are also subtypes of C1 and I. In our case here, the only such type is C2.
Here is also an attempt at showing that the code is correct based on the JLS3: Any type parameter is correct iff it is a subtype of all the types in the bound of the type parameter. To check this, you should take the capture conversion (JLS3 5.1.10) of "? super C2" which is a fresh type variable, let's say CAP, with the upper bound "C1 & I" which clearly is a subtype of the type parameter T as it has the same types in the bound. Or am I just missing something?

Similar Messages

  • How to add item to a List with a bounded wildcard

    Hi,
    Is there a way to add a subtype instance to a List with a bounded wildcard? For example, say I have an
    abstract class called Car. Then I have 2 concrete subclasses--Ford and Toyota. Now say I have another
    class that contains a prepopulated list and is wildcard bounded like this: List<? extends Car> carList. I
    want to add a method where I pass in a Car subtype as a parameter and then add it into this list, e.g:
    public void addCar(Car car) {
    carList.add(car);
    Trying this, I keep getting "cannot find symbol" compilation errors. When I went back to read the Generics
    tutorial by Bracha, he mentions that explicitly adding a subtype, e.g. carList.add(new Ford()), can not be
    done. But here I'm adding the "upper bound" of the wildcard, i.e. the Car type. Therefore there should be no
    discrepancy between supertype and subtype an thus the carList.add(car) should be ok, IMO.
    Am I misunderstanding something with this logic? Also, if carList.add(car) can not be done, then how can
    I go about doing something similar which will allow me to add subtypes to a "generic" list?
    Thanks in advanced!
    -los

    I get a compilation error expecting an Object instead of a Car. Of course you did. List<? super Car> is a list into which you can put cars -- and possibly other stuff. List<? extends Car> is a list out of which you can get cars (possibly of different makes).
    Do you need a list that you can put cars in and get cars out? That's List<Car>
    This isn't a linguistic problem you are having; this is a design problem. If you have a function that takes an argument which is a list that you can put any kind of car into and be sure of getting a car out of, it isn't reasonable to pass in a List<Ford> (because the function might put in a Chevy) or a List<Object> (but there might be motorcycles already in there). By the requirements you have, you need a List<Car> and nothing else.
    Yes, you could use a cast, but all you are doing is circumventing the type system by saying "I know this List<Object> only has Cars in it."

  • Bounded Wildcard prob

    Hi All,
    Below is what the description says about "super"
    You can also specify a lower bound for a wildcard by adding a super clause to a wildcard declaration. Here is its general form:
    <? super subclass>
    In this case, only classes that are super classes of subclass are acceptable arguments. This is an exclusive clause, because it will not match the class specified by subclass
    However, pls look at the following code. According to the above description the below code(printXY_1(c4) call) should not compile and run, however is is running properly. I am wondering if i've missed something. Pls comment. Thank you in advance.
    class TwoD
         int x,y;
         public TwoD(int a,int b)
              x=a;y=b;
    class ThreeD extends TwoD
         int z;
         public ThreeD(int a,int b,int c)
              super(a,b);
              z=c;
    class FourD extends ThreeD
         int w;
         public FourD(int a,int b,int c,int d)
              super(a,b,c);
              w=d;
    class Coordinates<T extends TwoD>
         T [] coords;
         public Coordinates(T [] o)
              coords=o;
    public class BoundedWildcards
         public static void main(String args[])
              TwoD [] t2={ new TwoD(1,2),new TwoD(4,5)};
              Coordinates<TwoD> c2=new Coordinates<TwoD> (t2);
              ThreeD [] t3={ new ThreeD(1,2,3),new ThreeD(4,5,6)};
              Coordinates<ThreeD> c3=new Coordinates<ThreeD> (t3);
              FourD [] f4={ new FourD(0,1,2,3),new FourD(4,5,6,7)};
              Coordinates<FourD> c4=new Coordinates<FourD> (f4);
              System.out.println("\nPrint X & Y co-ordinates");
              printXY_1(c2);
              printXY_1(c3);
              printXY_1(c4);     }
                        static void printXY_1(Coordinates<? super FourD> obj)
              for(int i=0;i<obj.coords.length;i++)
                   System.out.println("X: "+obj.coords.x+"\tY: "+obj.coords[i].y);

    This is an exclusive clause, because it will not match the class specified by subclassThat doesn't agree with what I have read. (And it doesn't agree with what I would expect, either.) And what I have read is the first 200 pages of Angelika Langer's Generics FAQ document, which repeatedly says that <? super X> includes X. It specifically says that <? super Object> is legitimate but can only be satisfied by Object.

  • Am i the only one that see's serious bugs with Windows Search index on Windows 8.1 and Office 2013?

    So i originally had Windows 8 and Office 2013 installed. I noticed that alot of my emails in Outlook 2013 as well as contacts werent being indexed. I waited for windows 8.1 and did an upgrade hoping the 8.1 would fix the issue. It didn't.
    So i formatted my hard drive, installed fresh windows 8.1, and office 2013, and let it Windows Index run. I see 2 things happening.
    A.) The indexer never completes
    B.) the indexer takes up 40% cpu usage.
    I tried rebuilding, creating index from new location, nothing seemed to work. I decided to prevent the indexer from searching Office apps (outlook and onenote) and low and behold it completes indexing. 
    I decided to try and format again and see if there was some bug causing the issue. So this week I formatted once agian, loaded Windows 8.1, installed updates, and loaded office 2013. Once again, my indexer
    is stuck around 70k items and my processor usage on Searchindexer.exe is around 30-40%.
    Is this a known bug with 8.1 and office?
    Brad Nelson MCSE/DCSE/A+/Network+/WCSP

    Hi,
    I test in my environment, and Windows would finish the index, the CPU usage keeps in 29%, which my RAM is 8G.
    Can you tell us how you let the Windows Index run?
    Alex Zhao
    TechNet Community Support

  • Issues / Bug with Nokia N9

    Issues / Bug with Nokia N9
    1. The mobile network gets disconnected after each call and I have to wait atleast 10-20 seconds to redial or make a new call, I cannot dial a number just after I finish a call / speaking with someone. It happens on both Incoming and outgoing Calls.
    Troubleshooting Steps:
    1. Changed SIM card from the telecom provider atleast 3 times. The same SIM card works absolutely fine in another mobile.
    2. Reset and set to default settings tried - No Result
    2. The ear piece volume is considerably low.
    Troubleshooting Steps:
    1. Reset and set to default settings tried - No Result
    3. When playing a video online on YouTube the timing for a 4 minute video shows as
        34:00 34:23 instead of showing 04:00 04:23
    Troubleshooting Steps:
    1. Reset and set to default settings tried - No Result
    4. The photos from the Facebook app built into the phone do not always load even If I am running a 3.5G Mobile Data connection or at Home on a Wi-Fi connection
     Troubleshooting Steps:
    1. Reset and set to default settings tried - No Result
    I am from India, bought the phone last year from Abu Dhabi and it is Made in Finland.
    Really I need someone to help me out here!!

    If you reinstalled the OS again from Nokia, you may just have a defective phone and there could be something wrong with the hardware.  I have two N9's and I haven't experience any of these problems.
    Can you record these problems and post the link to youtube here so I can see what's happening?
    I Choose Nokia!

  • BUG: Oracle Java Compiler bug with anonymous inner classes in constructor

    The following code compiles and runs just fine using 1.4.2_07, 1.5.0_07 and 1.6.0_beta2 when compiling and running from the command-line.
    It does not run when compiling from JDeveloper 10.1.3.36.73 (which uses the ojc.jar).
    When compiled from JDeveloper, the JRE (both the embedded one or the external 1.5.0_07 one) reports the following error:
    java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method: <init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
    stack
    Here's the code:
    /** lexical analyzer for arithmetic expressions.
    Fixes the lookahead problem for TT_EOL.
    public class Scanner extends StreamTokenizer
    /** kludge: pushes an anonymous Reader which inserts
    a space after each newline.
    public Scanner( Reader r )
    super( new FilterReader( new BufferedReader( r ) )
    protected boolean addSpace; // kludge to add space after \n
    public int read() throws IOException
    int ch = addSpace ? ' ' : in.read();
    addSpace = ch == '\n';
    return ch;
    public static void main( String[] args )
    Scanner scanner = new Scanner( new StringReader("1+2") ); // !!!
    Removing the (implicit) reference to 'this' in the call to super() by passing an instance of a static inner class 'Kludge' instead of the anonymous subclass of FilterReader fixes the error. The code will then run even when compiled with ojc. There seems to be a bug in ojc concerning references to the partially constructed object (a bug which which is not present in the reference compilers.)
    -- Sebastian

    Thanks Sebastian, I filed a bug for OJC, and I'll look at the Javac bug. Either way, OJC should either give an error or create correct code.
    Keimpe Bronkhorst
    JDev Team

  • Javac bug database still being maintained?

    After the Oracle acquisition, is the javac bug database still being maintained? I submitted a bug report on 04/20/2010 and received an e-mail response back confirming it was a new bug on 04/22/2010. The e-mail said it would be posted in the external database in "a day or two", but now 12 days later Bug ID [6946211|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6946211] is still not visible. I tried replying back to the e-mail but no response.
    If anyone's interested, here is the sample code I submitted with the bug report.
    public interface BaseType {
        BaseType clone() throws CloneNotSupportedException;
    public interface SubType<T extends BaseType & java.io.Closeable> extends BaseType {
    }It should compile correctly but fails. It appears to be a generics bug.

    I am rather certain that years ago (thus pre Oracle) it could take weeks before posted bugs showed up.
    And presumably this was discussed in the Generics forum before posting it as a bug.

  • Has anyone noticed a problem with low/no volume after update to iOS 8.1.3 ?

    HHas anyone noted a problem with low or no volume after update to iOS 8.1.3?

    Although this reply is late.  I just want to share that I have the same issue - no LTE after upgrade to 8.1.3 on my iPhone 5.  No matter switch on/off iPhone or LTE option or Airplane Mode -  they all didn't work....but after an upgrade to 8.2 today.  I got my LTE back now after a month...not sure if it is a bug or a reset work.  Good luck to anyone who looking for the resolution of same issue.

  • [svn:fx-trunk] 8452: - Fix flicker problem with constraint bound text that is being autoSized.

    Revision: 8452
    Author:   [email protected]
    Date:     2009-07-08 08:38:32 -0700 (Wed, 08 Jul 2009)
    Log Message:
    - Fix flicker problem with constraint bound text that is being autoSized.  If the remeasure is done in a 2nd pass you will see a flicker as all the objects are moved to accommodate the reflowed text.
    - Fix data binding issue with text setter.
    - Rework measure() to accommodate implicit autoSize.
    If explicitWidth or widthInChars specified and explicitHeight or heightInLines specified, or for now, blockProgression != "tb", the text has fixed dimensions and is not auto-sized.
    If no text and width specified, but no height, start at specified width and one line high and grow taller.
    If no text and height specified, start at 1 char wide with the specified height and grow wider.
    If neither width nor height specified, and toFit lineBreaks, start at explicitMaxWidth, or default maxWidth of 160, and grow taller.
    If neither width nor height specified, and explicit lineBreaks width is unlimited and can grow taller.
    These are further constrained by min/max Width and Height except in the case that explicitWidth or explicitHeight are specified.
    - Change default maxWidth for RichText and SimpleText to 160 to match RET.  Previously it was 10000.  This is used for
    text with toFit lineBreaks if a width isn't specified.
    QA Notes: 12 or so TextGraphic tests fail because of the new default maxWidth.
    Doc Notes:SDK-22014, SDK-21837
    Reviewers: Gordon
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22014
        http://bugs.adobe.com/jira/browse/SDK-21837
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/RichEditableText.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/supportClasses/GraphicEleme nt.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/supportClasses/RichEditable TextContainerManager.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/supportClasses/TextGraphicE lement.as
    Added Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/primitives/supportClasses/RichEditable TextEditManager.as

    You have used elements like header, footer, footer1 and nav without using the correct DOCTYPE declaration. Replace the first line of your code with
    <!doctype html>
    Also have a look here for other problems http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fhome.surewest.net%2Fstorytales%2F test%2Fforposting.html
    After the above has been fixed, please come back here to fix the remaining problem(s)
    Gramps

  • Bug with big Black Pixel on Photoshop CC

    Hi,
    I recently install Photoshop CC (iMac 2,8 Ghz Intel Core i5, 16Go 1333 Mhz DDR33, Mavericks)
    When using different layers, I have a HUGE BLACK PIXEL coming on the picture (365x365px) , often on the low lef corner.
    It disapears when I strongly zoom inside but it comes back when I zoom out...
    Any idea please ????

    Many thx Mylenium,
    it seems to be working right now without OpenCL... I also had a bug with zoom in and zoom out but it seems to be ok too...
    I hope it will continue..
    (I use to work on heavy pictures with many layers, hope everything will not be too slow without OpenCL)

  • Bug with highlighted text in Illustrator CS6

    Hi! I use AI CS6 on a mac book pro Lion 10.7
    I got a recurrent bug with the text tool.
    When I selct a text sometimes the highlight totally hide my text and it's difficult to edit it! I tried CMD+H and CMD CTRL+H but nothing works, even hide bounding box...
    As you can see... It's an issue to read and edit the text properly!
    And even in wireframe view CMD+Y texts appear like blocs!
    And besides this happen not on evry texts in the document.. I don't have a clue
    Very annoying!
    Anyone has the same problem? Solution is would be appreciated!
    Thanks
    Samy

    Hi SaCha_bxl,
    What you have done is, Switched on the "Show Hidden characters" option. U can hide it back by
    Clicking on "Type" (Which will be in navigation bar) and see if u have checked in "Show Hidden Characters " if so uncheck it and your problem will be solved.
    or you can also use the short cut " Alt+Ctrl+I "

  • Oracle instance running on a system with low open file descriptor

    Hello.
    We have 10.1.0.4 on SuSE 9 on x86 64bit Sun servers.
    We have databases that if started manually come up without the warning, but if started via a shell script scheduled through a crontab start up with this warning: "Oracle instance running on a system with low open file descriptor".
    My understanding is that it has to do with OS ulimit. it appears that non-interactive shell (crontab) does not set the nofiles at 65536.
    All our system are set up exactly the same way. The problem is, though, that some systems do not report the warning even when started non-interactively.
    My question is this: assuming my nofiles ulimit is in fact too low on all systems, why would some systems report the warning and others would not? Is there anything database specific the instance looks for when it starts, such as the number of datafiles in the database, instance memory size, etc..., which would make the instance warn in some cases but not the others?
    Thank You
    Boris

    Thank You Satish.
    This is a good reference and we may end up looking into the patch bundle associated with the bug.
    But does anyone have any idea why the systems that are set up the same exact way would warn on systems and not on others?
    Also, the Metalink note talks about init.crsd. I have not build an association between this inconsistency and RAC.
    What I do see is that if we start up our database non-interactively (where ulimit -n resolves to 1024, instead of 65536) the warning is generated, in some cases.
    Perhaps, the 1024 is too low. But then my question is why would Oracle think it is too low only on some servers and not all?
    Boris

  • A question about a method with generic bounded type parameter

    Hello everybody,
    Sorry, if I ask a question which seems basic, but
    I'm new to generic types. My problem is about a method
    with a bounded type parameter. Consider the following
    situation:
    abstract class A{     }
    class B extends A{     }
    abstract class C
         public abstract <T extends A>  T  someMethod();
    public class Test extends C
         public <T extends A>  T  someMethod()
              return new B();
    }What I want to do inside the method someMethod in the class Test, is to
    return an instance of the class B.
    Normally, I'm supposed to be able to do that, because an instance of
    B is also an instance of A (because B extends A).
    However I cannot compile this program, and here is the error message:
    Test.java:16: incompatible types
    found   : B
    required: T
                    return new B();
                           ^
    1 errorany idea?
    many thanks,

    Hello again,
    First of all, thank you very much for all the answers. After I posted the comment, I worked on the program
    and I understood that in fact, as spoon_ says the only returned value can be null.
    I'm agree that I asked you a very strange (and a bit stupid) question. Actually, during recent months,
    I have been working with cryptography API Core in Java. I understood that there are classes and
    interfaces for defining keys and key factories specification, such as KeySpec (interface) and
    KeyFactorySpi (abstract class). I wanted to have some experience with these classes in order to
    understand them better. So I created a class implementing the interface KeySpec, following by a
    corresponding Key subclass (with some XOR algorithm that I defined myself) and everything was
    compiled (JDK 1.6) and worked perfectly. Except that, when I wanted to implement a factory spi
    for my classes, I saw for the first time this strange method header:
    protected abstract <T extends KeySpec> T engineGetKeySpec
    (Key key, Class<T> keySpec) throws InvalidKeySpecExceptionThat's why yesterday, I gave you a similar example with the classes A, B, ...
    in order to not to open a complicated security discussion but just to explain the ambiguous
    part for me, that is, the use of T generic parameter.
    The abstract class KeyFactorySpi was defined by Sun Microsystem, in order to give to security
    providers, the possibility to implement cryptography services and algorithms according to a given
    RFC (or whatever technical document). The methods in this class are invoked inside the
    KeyFactory class (If you have installed the JDK sources provided by Sun, You can
    verify this, by looking the source code of the KeyFactory class.) So here the T parameter is a
    key specification, that is, a class that implements the interface KeySpec and this class is often
    defined by the provider and not Sun.
    stefan.schulz wrote:
    >
    If you define the method to return some bound T that extends A, you cannot
    return a B, because T would be declared externally at invocation time.
    The definition of T as is does not make sense at all.>
    He is absolutely right about that, but the problem is, as I said, here we are
    talking about the implementation and not the invocation. The implementation is done
    by the provider whereas the invocation is done by Sun in the class KeyFactory.
    So there are completely separated.
    Therefore I wonder, how a provider can finally impelment this method??
    Besides, dannyyates wrote
    >
    Find whoever wrote the signature and shoot them. Then rewrite their code.
    Actually, before you shoot them, ask them what they were trying to achieve that
    is different from my first suggestion!
    >
    As I said, I didn't choose this method header and I'm completely agree
    with your suggestion, the following method header will do the job very well
    protected abstract KeySpec engineGetKeySpec (Key key, KeySpec key_spec)
    throws InvalidKeySpecException and personally I don't see any interest in using a generic bounded parameter T
    in this method header definition.
    Once agin, thanks a lot for the answers.

  • 30EA3: German language bug with user defined reports still not fixed

    In 30EA2: Limited folder functionality with German language
    I wrote about a bug in 30EA2. Was this message noticed by the developers?
    The bug still exists in 30EA3.
    In new folders for user definded reports only the options "Kopieren" and "Exportieren" (copy and export) are available, when SQL-Deverloper runs in German language mode.
    A workaround is to force language to English with the line
    AddVMOption -Duser.language=en
    in sqldeveloper.conf

    I made a new thread for the same bug in 3.1EA2:
    3.1EA2 Old bug with German language settings still exists
    I have some hope, that my problem finally got noticed by the developers.

  • 3.1EA2 Old bug with German language settings still exists

    In the past I wrote several times about a bug in SQL Developer when running in German language mode. This bug is still not fixed in 3.1 EA2:
    In new folders for user definded reports only the options "Kopieren" and "Speichern unter ..." ('Copy' and 'Cave as') are available, when SQL-Deverloper runs in German language mode. Other options like "Bearbeiten, Neuer Ordner, Neuer Bericht, Ausschneiden, Einfügen, Löschen" (Edit, New Folder, New Report, Cut, Paste, Delete) are missing. A workaround is to force language to English with the line
    AddVMOption -Duser.language=en
    in sqldeveloper.conf
    I mentioned it first in Re: Folders with limited functionality about version 2.1.1.64 and then in 30EA2: Limited folder functionality with German language 3.0 EA2 and German language bug with user defined reports still not fixed Beta Release 3.0 EA3
    Edited by: user1775992 on 22.11.2011 03:30

    I have raised a bug on this issue and I am actively looking into it.

Maybe you are looking for

  • Strange...slide bar doesn't work..

    Strange, when I edit a photo and then go back to the rest, it won't let me use the slidebar (size changer) at the bottom right. I have to quit and reopen it, then works fine? ALSO, whenever I make a duplicate, it reverts to the very first photo in my

  • How to replicate a new pricing procedure from SAP ERP?

    Dear Experts, I have set up a new pricing procedure in the ERP backend and I would like to replicate this to SAP CRM. A replication using object DNL_CUST_CNDALL has been executed once in the past. What would be the best way for me to download the new

  • Date / Time Column Display

    I want to be able to display within a JClient panel two separate fields - one a date and one a time, but I want both of these to reference a single database column, extracting the relevant portion of the data for display to the user. I have tried man

  • Can't Open Any Programs

    I had been on Safari for awhile and had to leave the computer for about 10 minutes. When I came back the mouse is responsive, but nothing else is. I can't shut down any program or the computer. I did a forced shut down, and it starts back up just fin

  • Taking out IF's and returning a boolean expression

    I thought a better way to implement this later method might be to remove the IF's and just return a boolean expression true or false if one date object is later than another date object. I almost have it correct but one case is still not outputting c