Here's a good stumper. Any ideas? Java BUG?

public class Test {
    //A static value we will set later -- this is legal
    static final int INT_VALUE;
    static {
        //try to set the value..
        //note that an exception *could* be thrown BEFORE the value is set
        try {
            if (getValue()>50)
                INT_VALUE = 50;
            else
                INT_VALUE = 5;
        } catch (Exception ex) {
            //if there was an exception, the value wasn't set, so we do it now
            INT_VALUE = 1; // <-- javac will complain about this. why?
    static int getValue() throws Exception {
        throw new Exception("whoops");
}If you compile this, javac tells you the line
INT_VALUE = 1; is bad because the valriable might have been assigned to.
What order of operations could throw the exception and assign the value before the
INT_VALUE = 1; line is reached?

If you compile this, javac tells you the line
INT_VALUE = 1; is bad because the
valriable might have been assigned to.
What order of operations could throw the exception
and assign the value before the
INT_VALUE = 1; line is reached?The person who said the java compiler is dumb is just about right. The complaint that the compiler gives is that the value might be assigned already. This is beacuse the INT_VALUE varible has a chance to be assigned in the try block.
In your code you force a deterministic error which is usually not the case so the compiler doesn't search for it. Hence the compiler says that there is a chance that the value ha already been assigned. This is also because the value assignement, if it happened, will stay past the try block and the catch will try to reassign the final.
So the compiler just plays it safe and says the variable might have already been assigned rather than searching for possible exceptions and determining if the variable gets set to a value or not (remember your code is exceptionally deterministic with respect to the runtime error being thrown.)

Similar Messages

  • Hi there, i installed a system update earlier on my MacBookPro and now it wont connect to wi-fi, working through Network Diagnostics hasn't solved the issue.  all other devices here are connecting normally.  any ideas?

    hi there, i installed a system update earlier on my MacBookPro and now it wont connect to wi-fi, working through Network Diagnostics hasn't solved the issue.  all other devices here are connecting normally.  any ideas?

    Hi, this has worked for a few...
    Make a New Location, Using network locations in Mac OS X ...
    http://support.apple.com/kb/HT2712
    10.7 & 10.8…
    System Preferences>Network, top of window>Locations>Edit Locations, little plus icon, give it a name.
    10.5.x/10.6.x/10.7.x instructions...
    System Preferences>Network, click on the little gear at the bottom next to the + & - icons, (unlock lock first if locked), choose Set Service Order.
    The interface that connects to the Internet should be dragged to the top of the list.
    10.4 instructions...
    Is that Interface dragged to the top of Network>Show:>Network Port Configurations.
    If using Wifi/Airport...
    Instead of joining your Network from the list, click the WiFi icon at the top, and click join other network. Fill in everything as needed.
    For 10.5/10.6/10.7/10.8, System Preferences>Network, unlock the lock if need be, highlight the Interface you use to connect to Internet, click on the advanced button, click on the DNS tab, click on the little plus icon, then add these numbers...
    208.67.222.222
    208.67.220.220
    Click OK.

  • HT201269 My wife switched from an iPhone 4 to an iPhone 5.  Everything transferred over and service is on the new phone.  However, texts are going to her old phone still.  Any idea what the problem is?

    My wife switched from an iPhone 4 to an iPhone 5.  Everything transferred over and service is on the new phone.  However, texts are going to her old phone still.  Any idea what the problem is?

    As long as iMessage is enabled and the old phone is connected to a WiFi access point, it will continue to receive iMessage texts. It won't receive non-iMessage texts nor will it receive any calls.

  • HT201077 When my wife creates a Shared stream on her account it says it came from me with her Account. She is logged into her own separate Apple ID on both her phone and iPad. Any ideas how to separate?

    When my wife creates a Shared stream on her account it says it came from me with her Account. She is logged into her own separate Apple ID on both her phone and iPad. Any ideas how to separate?

    There are a lot of posts in the forums today with people having problems with iMessage.   There was also a published outage yesterday, so it's possible there are still some issues that may be impacting you both.
    I would just wait it out - I'm sure it will be sorted out soon.

  • I switched my number to my daughters iPhone 4 and she got an iPhone 5.  When I send txt using iMessage, she is getting a copy of the txt on her phone as well. Any idea on how to stop this?

    I switched my number to my daughters iPhone 4 and she got an iPhone 5.  When I send txt using iMessage, she is getting a copy of the txt on her phone as well. Any idea on how to stop this?

    This occurs when two people share the same apple id for imessage.
    settings - message - send & receive - uncheck or remove the apple id.
    do the same for start a new conversation.

  • HT1222 iPhone 5s won't turn on after this update. Battery was at 98%, tried holding sleep & home button while plugged in, no good. Any ideas?

    iPhone 5s won't turn on after this update. Battery was at 98%, tried holding sleep &amp; home button while plugged in, no good. Any ideas?

    P.S. I just noticed; when I hold the power and home button at the same time while it's plugged in as if I was going to restart it, my computer acts as if I'd plugged it in again (it makes the USB notification sound, itunes opens up again, I get the same "your iphone is in recovery mode" message, etc.), but that's the only response I've been able to get from pressing anything on the iphone. thanks again.

  • Hello, My  i Mac is  from 2008, the unit at times doesn't start up.(mouse lights then off with no screen) I ran Mackeeper thinking its a  virus, but not. My unit is plugged into a volt regulator  its a US unit 110v and here in philippines 220 V, any ideas

    Hello, My I Mac is a 2008 unit. Quite offen it will not power on, mouse lights then it goes off with no screen even if i press control/command rp keys.
    Some other information the unit is from USA, a 110V and now in Philippines which is 220V I have it on a 110 voltage regulator.(can i plug in to 220 v directly?) I also ran MacKeeper thinking it could be a virus, but its not, i notice if i leave unit on without shut down, the problem occurs less, thinking its a battery problem but I'm not sure.
    Here in Philippines we have no Mac stores and service is not like  in the USA. Any ideas of what wrong?

    MacKeeper is highly invasive malware that can de-stablize your operating system. It is also unethically marketed and a rip-off.
    Further opinion on it and how to uninstall MacKeeper malware:
    http://applehelpwriter.com/2011/09/21/how-to-uninstall-mackeeper-malware/
    This is also worth reading:
    http://www.reedcorner.net/news.php/?p=245
    It sounds like a faulty power unit. You need to get it professionally checked.

  • Recording from DJ equip to garage band and quality is not good?Any ideas

    I Dont know what has changed It was ok before.I have tried changing from mono to stereo and different settings on my amp and mixer. Sounds fine when playing but when I listen back on garageband or Itunes It sounds as if i am playing in the red on the laptop? I have to have the volume all the way up on garageband else it doesnt seem to record anything. Have tried adjusting the volume in the sound section on the laptop. Have done all the updates and everything. Does any one have any ideas please!?

    What is your OS X version?

  • I live in a mobile home in Torrance, CA which gets good reception with my LG phone, but my Iphone 4 doesn't get good service, any ideas ?

    Hi and thanks for any enlightment on this subject in advance! I recently purchased a iphone4 and it doesn't get as good as reception as my LG old phone does in my mobile home in Torrance, CA . I turned the phone on and off and also removed and reinstalled the sim card. Of course both phones were operating with the same carrier which is at&t. Any other Ideas I might try?

    This is vewry interesting ... I have the exact same problem (distorition with high frequencies when playing ipod music @ 320mbps) with my wife's iphone 4 using bluetooth through the  JVC KWXR816 but not through my iphone 4. Mine plays perfect. 

  • HT1349 I have lost sound. It's ok with headphones and the ring tone works but otherwise no sound. I've restarted, checked the mute lock and bottom of page when right swiped etc and all no good. Any ideas

    I've lost the sound on my I pad 2. It works ok with headphones but not without. Mute is definitely not on. Have restarted and reset. Any other ideas?

    See this link - http://support.apple.com/kb/HT4085
    Others have reported exactly like you but have since found that settings had changed!

  • I upgraded to iOS5 and now the vibration alert feels like the phone is dying. The battery life is still good. Any ideas?

    The intensity of the vibration alert dropped to almost nothing followign the upgrad to iOS5.

    It will not help. I have tried that. I have even put my Phone in Airplane mode to make sure it closes all APPS but it simply doesnt help. Join the gang!
    My frustation is that I got the phone for all the features it offers and if I cant use those features what good does the phone do?

  • The best way to remove any " Fake java bug" from the Mac  ??

    I upgraded my OS to "yosemite" from Mavericks, simultaneously a java upgrade requirement started to pop up, i upgraded that very java update & since then continuously receiving the very same update again & again.. which will be the best way to remove that bug, if it is one.....!!!!!! ??

    Java for OS X 2014-001

  • I cannot access Yahoo Games on my Mini after the latest Java upgrade. This has happened before. Any ideas? Thanks!

    When I try to access Yahoo Games Bridge the system will not allow me to download the applets necessary. This has happened before after a software update and it is a complete pain. I can go back to a old version of Java but the security is apparently not good. Any ideas? Thanks!
    Jack

    Thanks lllaass but I have enabled Java. I did manage to get into the site by setting the Java security level to the lowest setting. There was a warning but it did let the site load after I excepted the risk. Thanks again!

  • I have a 2012 MacBook Pro running OSX 10.8.5. I am noticing that when I try to drag an icon accross the screen it tends to stick for 5 to 10 seconds. Just did a reformat and reinstall of OS but no change. Any ideas?

    when I try to drag icons accross the screen thet are sticking for up to 10 seconds. I have just done a recovery (reformatted and reinstalled the OSX 10.8.5 but no change. The activity monitor shows nothing out of the ordinary. I have a MacBook Pro 2012. I am having perfomance isues with ProTools and I'm wondering if the 2 are connected. I installes TechTools 7 and ran tests on everything and it says all is good. Any idea's? Thanks!
                                                                                                                                                               Jim

    If you haven't already done so, eject the card by dragging its icon to the Eject icon in the Dock (where the Trash icon usually is.) Make sure the write-lock switch on the card is in the unlocked position. Then reinsert the card and test.
    If there's no change, and the same happens with more than one card, the card reader is stuck in write-locked mode. I don't generally advise do-it-yourself hardware repair, but one ASC member managed to fix this problem. I haven't tried the fix myself and I can't offer any guidance beyond what's in that discussion. If you cause damage, don't expect your warranty to cover it. I suggest you instead make a "Genius" appointment at an Apple Store.

  • Any Ideas on animated flying windows (video)

    Here is the video. Any ideas on how this was done?
    http://youtu.be/uahNE-vcsYs
    Thanks
    I am using Premier Pro CS6.

    The reason it doesn't look like the example is because the person most likely used after effects or another program similar to after effects just like Jim previously mentioned. After effects allows you to use a camera in your comp which is why when they "pan" everything moves together it's because they are using a camera so the camera is what is moving not the single object like you can do in Premiere using the basic 3d effect.
    If you want to make it truly look like your example your going to have to use after effects. Premiere isn't made to do things like that. Here is a site that will help you do things simlar to what you're wanting. This specific tutorial will show you how to use a camera in after effects using the "sure target" preset although you can totally do it without the sure target preset. The sure target preset just automates things for you a bit.
    http://www.videocopilot.net/tutorials/energetic_titles/
    The only thing I have ever been able to do in Premiere to mimic a after effects camera is too nest a bunch of the "floating items" then keyframe them out at the exact same time you're keyframming the new items in. Although honestly at that point it really becomes way easier to just use after effects. Basically though in after affects you can do exactly what your example did by simply using a camera layer.

Maybe you are looking for

  • Booting with 3.14.* results in unexpected shutdown

    Problem description: Computer boots normally up until the moment before NVIDIA splash and entering login screen (quiet disabled shows no errors), but upon trying to do so suffers abrupt shutdown. Some cases the computer screen goes blank, followed by

  • Recent upgrade to 3.1.2 and issue with voicemail password request

    just went thru the 3.1.2 upgrade, froze my original phone-just like the 3.1 upgrade- had to go to store and get a new refurshied phone (dont even go there!) which only worked for three days, then had to return to store again......excuse me, i do soun

  • Photoshop CC asks for serial number

    Hi all, Photoshop Creative Cloud, which I just subscribed to, is asking for a serial number. Adobe tech support told me to sign out, check connectivity issues, etc, and its not working. I think this is probably connected to an attempt someone made on

  • Can't log in to iCloud after upgrading to iOS8

    I recently upgraded my iPad 2 to iOS8. When I attempted to use an iCloud enabled app, ie. the Calendar, an alert pops up telling me to accept the iCloud terms and conditions. When I choose to continue in order to do so, it directs me to settings. How

  • Downloading Photoshop Elements 13

    I purchased Adobe Photoshop Elements 13 and Adobe Premiere Elements 13 and have gone online to get the serial numbers. I am using a new MacBook Air with out a CD-ROM. IS there anyway to download the software online without using the CD. Or, can I dow