System.exit(int) and javac def-use calculation

I'm wondering if anyone can tell me why javac (J2SE v1.4.2) seems to ignore "System.exit(int)" (alternately, "Runtime.getRuntime().exit(int)") for the pursposes of determining possible variable access before an initialization.
For example, consider the following code:
/*01*/  public class C {
/*02*/    public void foo() throws Exception {
/*03*/      C obj;
/*04*/      while (true) {
/*05*/        try { obj = new C(); }
/*06*/        catch (Exception fault) { System.exit(1); }
/*07*/        obj.foo();
/*08*/      }
/*09*/    }
/*10*/  }Compile this (ignoring the absurdity of what "foo()" actually does), and you will get a variable obj might not have been initialized error. This despite the fact that a call to "System.exit(int)" never returns normally, by definition. To illustrate why this error doesn't make sense, substitute the "System.exit(1)" of line #6 with any of "break", "return", or "throw new Exception()". The use calculation for variable 'obj' is correct in these three alternate situations, but not for the first, even though the situation is analagous.
Obviously, there is an easy work-around to this (viz., change line #3 to "C obj = null;"), though it seems unnecessary. Any ideas?

System.exit() doesn't have the same "special" meaning
to the compiler as "break", "return", or "throw" do.
As far as the compiler sees, you are simply calling a
method in your exception handler; it doesn't know
that there will be no return from that method. Sure,
the compiler could special-case System.exit(), but
then you'd still see this same problem if you came up
with your own wrapper method that calls
System.exit().. the compiler in general doesn't (and
shouldn't) assume that a method call will terminate
the app.I understand that "System.exit(int)" is merely a method from the perspective of the compiler, but it is a rather special method (actually the "Runtime" version, for which the "System" version is merely a wrapper) with respect to correct program execution, calculated during the various traces that are done during compilation. And wrapping "System.exit(int)" with another method wouldn't make any difference to the calculation if it was considered, from the perspective of compilation, an uncaught (implicitly declared non-Runtime) exception. Besides, there must be some execution sequence within "Runtime.exit(int)" that serves, essentially, the same function as an "exit" keyword.
What's wrong with supplying a default value when you
declare the variable?Absolutely nothing, except that it isn't necessary. I typically do so anyway, and only came across this "feature" of javac during a lapse of my coding standards.

Similar Messages

  • System.exit( int status );

    What's diference between System.exit(0); and System.exit(-1);
    What mean "int_status"

    Some shells allow you to handle the status code and do useful things with it. Taking bash as an example, you can use && and || to get another program to execute after your Java program only if the Java program respectively did or didn't return 0 (success exit code, and the default if you don't use System.exit and don't throw a RuntimeException out of main); you can use the $? environment variable to get the value returned (as a byte), and thus handle different error conditions differently (using test, for instance).
    So return 0 if execution was clean, or non-zero if something went wrong.

  • I found the operating system very confusing and hard to use. No tutorial. Manual and online help were outdated.  Tool bars, programs and documents randomly appeared and disappeared. Programs I installed completely disappeared. Anyone else experience this?

    I found the operating system very confusing and hard to use. No tutorial. Manual and online help were outdated.  Tool bars, programs and documents randomly appeared and disappeared. Programs I installed completely disappeared. Anyone else experience this?

    No need to apologize, Jim.  I think your rant was justified.  For years people have been telling me how easy the Mac was to use.  Imagine my frustration when I finally learned from friends and users that it takes weeks or months to make the transition from Windows to Mac.
    Still, I agree that I acted to too hastily when I returned my mini-mac to the store only three days after I bought it.
    I'm going to try again, this time with an iMac.  This time I'll keep it.  Since this thread is for the mini-Mac only, I'll probably be starting a new one for the iMac.
    Why did I decide to try again?  Well, I do like the faster speed and compact hardware of the Macs.  I also like the fact that I can install Windows and use that for my programs until I transition completely to Mac, IF I make the complete transition.
    Thank you all for your suggestions and advice.  I have paid attention to what you said.
    Andy

  • System.exit(int) - Just For Fun

    import java.applet.*;
    public class BrowserKill extends Applet {
      public void init() {
        System.exit( 0 );
    }Terminate JVM while the browser is trying to contact JVM.
    Wow ... I've tried this code in IE 6.0 ... It crashed my browser ...
    What do you think ?
    You can try this code in JSP/Servlet ...
    I'm sure that the server will be crashed. (Because of terminating JVM)

    Wow ... I've tried this code in IE 6.0 ... It crashed my browser ...
    What do you think ?Serves you right for using such a rubbish browser. The security manager should have trapped the call and thrown a SecurityException, killing the applet but not the VM.

  • Is System.exit() a good call to use?

    I have a program that checks for updates in the db. If there are no updates in the database I want the program to stop. There are also many other conditions that would cause the program to stop. None of them are "Errors" so I wasn't using Exceptions to end the program The program runs from a command line or from chron job. Is it safe / OK to use System.exit() to do this?

    As you describe it, I'd say yes. System.exit() is the way to end your program.
    The danger of System.exit() is if a class you write will be reused in some other system. In that case, System.exit() could be entirely inappropriate in that context, thus preventing your class from being reusable.
    If you only call System.exit() in your main() method, you'll probably be OK.

  • System.exit( int )

    What is the difference between System.exit( 0 ), System.exit( 1 ), System.exit( 2 ), etc.???

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#exit(int)

  • System.exit(VALUE) and Windows 98?

    Has anyone got System.exit(integer) to return a value other than 0 under Windows 98?
    Regardless of what integer I enter as an exit code, java.exe always seems to return 0. This does not seem to be the case under Windows NT, where the correct exit code is passed back.
    Is anyone aware of this problem/found a workaround?

    I found the same behaviour of Java between NT 4.0 SP 4 and Windows 98.
    Are you sure you get the exit code right in the dos box?
    %ERRORLEVEL% is NT specific, I think.
    In normal DOS you can only ask e.g.:
    if ERRORLEVEL 3 goto three
    and this will jump to label
    :three
    if the exit code is >= 3 !!!
    Test your program by this bat file:
    java ...
    if %errorlevel 6 goto x6
    if %errorlevel 5 goto x5
    if %errorlevel 4 goto x4
    if %errorlevel 3 goto x3
    if %errorlevel 2 goto x2
    if %errorlevel 1 goto x1
    goto x0
    :x0
    echo was: 0
    goto end
    :x1
    echo was: 1
    goto end
    :x2
    echo was: 2
    goto end
    :x3
    echo was: 3
    goto end
    :x4
    echo was: 4
    goto end
    :x5
    echo was: 5
    goto end
    :x6
    echo was: 6
    goto end
    :end
    echo End.
    You see:
    7 or higher goes also to :x6

  • Shared file system between Int and ext server(DMZ) in R12.1.3 for iRec

    Dear Friends,
    we are using R12.1.3 and we planned to use iRec module.
    so we decided to go with External web tier and it will be placed in DMZ for external users.
    Is it possible to have shared file system between internal and external web server when external server is in DMZ?
    Is it safe to go with shared application Tier file system between internal and external server (or) to have seperate file system in externel web tier?
    Regards,
    DB

    Take a look at Note 380490.1 DMZ Deployment for R12.
    Also For Specific Load balancer 727171.1 Up to 12.x but alot of the information is still usefull based on hardware loadbalancer
    Also Note 1309013.1 has some good information on SSO/OAM Intergration with E-Business Suite

  • System.exit(int exitCode)

    All my time as a Java programmer has been spent exiting programs using a zero (for OK) or a one (for error) without understanding what these ints mean or do. Can anyone clear up this little mystery and let me know what use the exit codes have and what the JVM does with them?

    All the JVM does is pass them to the shell. However, some shells allow you to detect them. For example, GNU grep has exit code of 0 if matches were found, 1 if no matches were found, or 2 if there was a syntax error in the pattern, or a system error. In bash you can get the exit code of the most recent process as $?
    For example: $echo aaa | grep aaa - ; export errorCode=$? ; \
        if [ $errorCode == 0 ] ; then echo Matches ; \
        elif [ $errorCode == 1 ] ; then echo "No matches" ; \
        else echo Error ; fi
    aaa
    Matches
    $
    $echo bbb | grep aaa - ; export errorCode=$? ; \
        if [ $errorCode == 0 ] ; then echo Matches ; \
        elif [ $errorCode == 1 ] ; then echo "No matches" ; \
        else echo Error ; fi
    No matches
    $
    $grep aaa /tmp/non.existent.file ; export errorCode=$? ; \
        if [ $errorCode == 0 ] ; then echo Matches ; \
        elif [ $errorCode == 1 ] ; then echo "No matches" ; \
        else echo Error ; fi
    grep: /tmp/non.existent.file: no such file or directory
    ErrorHTH.

  • Subject: Where are SAP Exit Variables and how to use them in Bex Query

    I have seen references to variables:  0cyear (Current Year), 0CALYEAR (current year), oCALMONTH (Current month/year).
    Under 0CALMONTH characteristic or 0CALYEAR I do not see any of the variables, so how does
    one use these variable in the query. For example I want to create a restricted key figure:  Duration restricted by Current calendar year (e.g.  2009 if I am in 2009, 2010 if I am in 2010..).

    Thanks a lot. Actally, I was looking in my production system and under varaiables I did not find any SAP Exit variables,
    but in development envrionment I do see some.
    Why will it not show me these variables in production? Is it because:
    1. Some special premssion is required to view this type of variable
    or
    2. THese varaiables were not installed from Business Content
    It is hard for me to beleive, it is permission issue.

  • System highly unstable and crashes while using Bluetooth (Plantronics)

    I got the new Macbook Pro with Leopard 10.5.6 and "some what" happy with the performance. OS looks to be buggy, in particular while using bluetooth devices or with high load and I have uploaded crash dumps couple of times to apple (support listening??) . I observed that when I use the Plantronics Pulsar 590A (http://www.plantronics.com/northamerica/enUS/products/cat1150057/cat5420035/prod29780013) watching video (iTunes, iMovie) the headset behaves strange i.e after all the hassle of going through the frequent connectivity issue (for which there's a question pending with no answer ), the sound drops or there's some crackling noise etc.
    More annoying problem is that the system crashes very frequently. i.e. while using the BT headset, watch video or listen to music for couple of minutes, close the app or put the system to sleep, then after some time try watching or listening some thing else, the system becomes unbelievably slow and finally gives up with an error message - Kernel panic, system needs to be restarted. Hold down the power button for several seconds or press the Restart button. If I don't use the bluetooth head set, the crashes are not so frequent but will crash for sure (I extensively use Virtualbox with one or two guest oses and most of the other crashes are from Virtoalbox)
    Also I observed that the Microsoft NB 5000 mouse also behaves odd i.e. Connection keeps getting dropped.
    Any ideas/suggestions ? I think this is the problem with Mac OS bluetooth driver as both these devices works without any problem on Windows XP/Vista on other hardware (not Mac x86).

    Try reinstalling OS X:
    How to Perform an Archive and Install
    An Archive and Install will NOT erase your hard drive, but you must have sufficient free space for a second OS X installation which could be from 3-9 GBs depending upon the version of OS X and selected installation options. The free space requirement is over and above normal free space requirements which should be at least 6-10 GBs. Read all the linked references carefully before proceeding.
    1. Be sure to use Disk Utility first to repair the disk before performing the Archive and Install.
    Repairing the Hard Drive and Permissions
    Boot from your OS X Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger.) After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list. In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive. If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported, then quit DU and return to the installer.
    2. Do not proceed with an Archive and Install if DU reports errors it cannot fix. In that case use Disk Warrior and/or TechTool Pro to repair the hard drive. If neither can repair the drive, then you will have to erase the drive and reinstall from scratch.
    3. Boot from your OS X Installer disc. After the installer loads select your language and click on the Continue button. When you reach the screen to select a destination drive click once on the destination drive then click on the Option button. Select the Archive and Install option. You have an option to preserve users and network preferences. Only select this option if you are sure you have no corrupted files in your user accounts. Otherwise leave this option unchecked. Click on the OK button and continue with the OS X Installation.
    4. Upon completion of the Archive and Install you will have a Previous System Folder in the root directory. You should retain the PSF until you are sure you do not need to manually transfer any items from the PSF to your newly installed system.
    5. After moving any items you want to keep from the PSF you should delete it. You can back it up if you prefer, but you must delete it from the hard drive.
    6. You can now download a Combo Updater directly from Apple's download site to update your new system to the desired version as well as install any security or other updates. You can also do this using Software Update.
    Some third-party peripherals may not be compatible with OS X. This may be especially a problem with peripherals that use proprietary drivers such as mouse software. If you are using Microsoft's driver software with your mouse consider uninstalling the software and driver. If this helps with your mouse, then you might try using SteerMouse - VersionTracker or MacUpdate - instead of the Microsoft software.

  • How to "kill" AWT Event Queue thread without using System.exit()?

    When I run my program and the first GUI window is displayed a new thread is created - "AWT-Event Queue". When my program finishes, this thread stays alive and I think it causes some problems I have experienced lately.
    Is there any possibility to "kill" this thread without using System.exit() (I can't use it for some specific reasons)

    All threads are kept alive by the JVM session. When you use System.exit(int) you kill the current session, thus killing all threads. I'm not sure, though...
    What you could do, to make sure all threads die, is to make ever thread you start member of a thread group. When you want to exit you app, you kill all the threads in the thread group before exit.
    A small example:
    //Should be declared somewhere
    static ThreadGroup threadGroup = new ThreadGroup("My ThreadGroup");
    class MyClass extends Thread {
    super(threadGroup, "MyThread");
    Thread thread = new Thread(threadGroup, "MySecondThread");
    void exit() {
    //Deprecated, seek alternative
    threadGroup.stop();
    System.exit(0);
    }

  • Why isn't System.exit(0) used from an Applet

    I am trying to figure out why the System.exit(0) method isn't used for an applet. Is it because an applet isn't an application (which is why the public static void main(String args[]))?
    I have noticed when if I include System.exit(0) I will get an compilation error.
    Is there someplace in the Java Tutorial that explains this?
    thanks

    You can put it in, but if you run it in a browser, it
    will kill the browser and all its windowsThat is if the applet is signed. I have also noticed this behaviour and I think it is pretty weird. It looks like a bug to me.

  • Avoiding system.exit(0)

    Hi
    I am using an external .jar file in my java program for parsing a file. My problem is that its main method has System.exit statement in the end i.e after parsing it exits the application. So when i use it my application also gets terminated. I have decompiled it and the only accessible method is main method. Is there any way to avoid this system.exit(0) ?

    EJP wrote:
    You can run it under a SecurityManager and a .policy file which doesn't grant that permission.I am trying to overrite securityManager functions:
    like:
    private static void forbidSystemExitCall() {
        final SecurityManager securityManager = new SecurityManager() {
                @Override
          public void checkPermission( Permission permission ) {
                    System.out.println("persmiion");
            if( "exitVM".equals( permission.getName() ) ) {
             throw new SecurityException("System.exit attempted and blocked.");
                @Override
          public void checkExit(int exit)
              super.checkExit(exit);
              throw new SecurityException("System.exit attempted and blocked.");
        //System.setSecurityManager( securityManager ) ;
      }and calling above code as:
                 try
                        forbidSystemExitCall() ;
                        try
                           Main.main(strings);
                        catch( ExitTrappedException e )
                        finally
                          enableSystemExitCall() ;
                   catch ( Exception ex)
                       System.out.println("error calling main method");
                       ex.printStackTrace();
                   }but above code is not working as i requried.
    Or if you have stuff to do on exit you can add shutdown hooks, see java.lang.Runtime.i could not understand it, please kindly can you explain little bit more... I have not play with java security before.
    BR
    Umer

  • Prevent System.exit(0)

    Hi Everybody!
    I have the following problem.
    I am developing an web-application running on a Tomcat server.
    Furthermore I am using some additional libraries, from which I only have the class-files. Nevertheless I decompiled them and found, that one method calls a System.exit(0) in its catch block, and this is horrible, because the server always shuts down in case of failure.
    What shall i do to prevent this? Altering the library will not be possible. Any ideas?
    I created a small example to point out my problem:
    public class Testing {
         private void methodA(String s) {
              try {
                   int i = Integer.parseInt(s);
                   System.out.println("Value of i: " +i);
                   Thread.sleep(1000);
              catch (Exception e) {
                   e.printStackTrace();
                   System.exit(0);
         }     //methodA
         public static void main(String[] args) {
              Testing t = new Testing();
              for (int i = 0; i < 10; i++) {
                   if (i == 5)
                        t.methodA("a");
                   else
                        t.methodA(String.valueOf(i));
              }     //for
    }Just think of methodA() as an method that can not be altered... How can I force the for-loop to continue when methodA() fails?
    (This is not my actual problem, but it points out my problem... ;)
    Thanks in Advance!
    Stef

    I was able to solve the problem by using the following code :-
    final SecurityManager securityManager = new SecurityManager()
         public void checkPermission(Permission permission)
              //This Prevents the shutting down of JVM.(in case of System.exit())
         if ("exitVM".equals(permission.getName()))
         throw new SecurityException("System.exit attempted and blocked.");
    System.setSecurityManager(securityManager);
    Hope it helps some one ..................... ;)

Maybe you are looking for

  • Delete photos from iPod Touch

    Need some help with this PLEASE!? I added some photos on my ipod touch by iTunes, & now I want to delete them but I don't know how. I tried to delete them on my ipod but I couldn't because they are in a new album & they also exist in another album on

  • IPod touch crashed with white screen after using Griffin TuneJuice

    Hello all, I have an iPod touch first generation that has worked flawlessly for about 1,5 years. Recently I bought a Griffin TuneJuice (external battery) to get longer battery life. The salesperson said it should work with the Touch, and it did at fi

  • How do I redeem a gift card in the South African storefront?

    How do I redeem a gift card in the South African storefront?

  • Javascript PopUp Page Passing Values

    Hi, I have a page which I am redirecting to from a report link column. The Column Link... URL is as follows: javascript:popupURL('f?p=&APP_ID.:8:&SESSION.::&DEBUG.::P8_SOURCE:#EXPRESSION#' ); My problem is that some values in #EXPRESSION# contain com

  • Importing a .mov for editing in FCP

    I am working on a project for a client where they had me import a bunch of VOB files from DVDs for the purpose of editing and exporting in a Windows/PowerPoint friendly format like .wmv. I'm using mpeg streamclip to convert the VOB files. Many of the