Plw-06002 unreachable code

Hi,
I am getting error PLW-06002 unreachable code at quite a few places . I guess my loops have some problem
but I am not able to find out reason for that. I apologize for inconveinence caused by unformatted code.
I have tried to format it, please help me to fix this mess.
create or replace procedure wip_case2_proc (p_packing_id IN     packing.packing_id%TYPE,
                                         p_new_qty    IN     NUMBER,
                                                               o_return_msg OUT VARCHAR2 )
is
v_tran                        VARCHAR2(1);
v_new_qty                 NUMBER;
v_new_line_status        VARCHAR2(5);
v_err_msg                   VARCHAR2(100);
vo_order_number          orders.order_number%type;
v_line_status                 ordered_items.status%TYPE;
ordadjrec                    orders%ROWTYPE;
itemrec                      ordered_items%ROWTYPE;
v_msg                      VARCHAR2(200);
v_client                    VARCHAR2(20);
v_order_number          VARCHAR2(20);
ordrec                     orders%ROWTYPE;
ord                        orders.order_number%TYPE;
oirec                      ordered_items%ROWTYPE;
    CURSOR c_packing IS
        SELECT p.client,
                   p.order_number
        FROM  packing p,
                 packing_attributes pa,
                 orders o,
                business_partner bp
    WHERE  p.packing_id       = p_packing_id
      AND  p.packing_id       = pa.packing_id
      AND  p.client           = o.client
      AND  p.order_number     = o.order_number
      AND  o.client           = bp.client
      AND o.business_partner  = bp.business_partner;     
CURSOR c_adj_item (p_order_number VARCHAR2, p_client VARCHAR2) IS
SELECT oi.*
   FROM   ordered_items oi, packing_details pd
  WHERE oi.order_number    = p_order_number
    AND   pd.packing_id      = p_packing_id
    AND  oi.client          = p_client
    AND  oi.ordered_item_id = pd.ordered_item_id
    AND  oi.stock_number    = pd.stock_number;
CURSOR c_adj_order (p_order_number VARCHAR2, p_client VARCHAR2) IS
SELECT *
   FROM orders
  WHERE order_number = p_order_number
    AND client       = p_client;
   CURSOR c_lines (p_order_number VARCHAR2, p_client VARCHAR2) IS
  SELECT oi.*
   FROM   ordered_items oi, packing_details pd
  WHERE oi.order_number    = p_order_number
    AND   pd.packing_id      = p_packing_id
    AND oi.client          = p_client
    AND status             = 'B'
    AND oi.ordered_item_id = pd.ordered_item_id
    AND oi.stock_number    = pd.stock_number ;
   CURSOR c_back_order(p_order_number VARCHAR2, p_client VARCHAR2) IS
   SELECT o.*
     FROM packing p,
              packing_attributes pa,
             orders o
    WHERE p.packing_id   = p_packing_id
      AND   p.packing_id   = pa.packing_id
      AND   p.client       = o.client
      AND   p.order_number = o.order_number
      AND   o.order_number = p_order_number;
  -----------------------------MAIN---------------------------------
BEGIN
     DBMS_OUTPUT.put_line ('adjust c_adj_item packing');
    ---adjust 
         v_tran         := 'U';
                  v_line_status  := 'S';
     v_new_qty      := p_new_qty;
  OPEN c_packing;
     Loop
         Fetch c_packing into v_client,v_order_number;
         OPEN c_adj_item (v_order_number, v_client);
            LOOP
                FETCH c_adj_item INTO itemrec;
           DBMS_OUTPUT.put_line ('adjust c_adj_order packing');
              OPEN c_adj_order (v_order_number, v_client);
                 FETCH c_adj_order INTO ordadjrec;
           cmn_backorder_pkg.adjust_order_items(v_tran,
                                                         ordadjrec,
                        itemrec,
                        v_new_qty,
                            v_line_status,                                                     v_msg);                                                                          
                                    CLOSE c_adj_order;
                             END LOOP;
                      close c_adj_item;
      DBMS_OUTPUT.put_line ('open c_back_order');
     OPEN c_back_order(v_order_number, v_client);
         LOOP
            FETCH c_back_order INTO ordrec;
            EXIT WHEN c_back_order%NOTFOUND;
          OPEN c_lines (v_order_number, v_client);
              LOOP
                 FETCH c_lines INTO oirec;
                  EXIT WHEN c_lines%NOTFOUND;
      wip_pkg.create_bo_item (oirec, v_order_number);
                  END LOOP;
          CLOSE c_lines;
      wip_pkg.create_new_backorder (ordrec);
                            END LOOP;
                   CLOSE c_back_order;
     END LOOP;
           CLOSE c_packing;
  o_return_msg := '0';
    EXCEPTION
       WHEN OTHERS THEN
        ROLLBACK;
  o_return_msg := 'WIP reversal error: ' || SQLERRM;
   END wip_case2_proc;Edited by: sandy162 on May 1, 2009 1:44 PM

Hi,
sandy162 wrote:
Sorry for inconveience, I have formatted code..That's a step in the right direction.
Now make the formatting reflect what you're doing: in particular, where the loops begin and end.
That is, you posted
         OPEN c_adj_item (v_order_number, v_client);
            LOOP
                FETCH c_adj_item INTO itemrec;
           DBMS_OUTPUT.put_line ('adjust c_adj_order packing');
       that makles it look like the call to put_line is outside of the loop.
I would suggest something like:
         OPEN c_adj_item (v_order_number, v_client);
         LOOP
                FETCH c_adj_item INTO itemrec;
                DBMS_OUTPUT.put_line ('adjust c_adj_order packing');Don't forget to indicate the 2 or 3 lines that you added since the last time the code ran without erros, and post the complete error message.

Similar Messages

  • Warning(3806,7): PLW-06002: Unreachable code

    Why do I got this warning:
    Warning(3806,7): PLW-06002: Unreachable code
    for this code:
    if p_ws = 'D' then
    raise_application_error(-20020, 'My Error');
    else -- <--Here
    return;
    end if;
    Thank you in advance.
    P.S. p_ws is of varchar2 type.

    user504063 wrote:
    Why do I got this warning:
    Warning(3806,7): PLW-06002: Unreachable code
    for this code:
    if p_ws = 'D' then
    raise_application_error(-20020, 'My Error');
    else -- <--Here
    return;
    end if;
    Thank you in advance.
    P.S. p_ws is of varchar2 type.Why return? This really seems to do nothing to me.
    Your code is identical to
    if p_ws = 'D' then
         raise_application_error(-20020, 'My Error');
    end if;So the compiler warning might be a good hint. The else part is not needed (although it is reachable...).
    Some warnings can be ignored, but in general I would try to look careful and understand what seems to disturb the compiler.
    Edited by: Sven W. on Mar 26, 2009 11:45 AM

  • Defect: Compiler wrongly complains about unreachable code.

    Here is a packaged procedure body for a procedure that is listed in the package spec:
    PROCEDURE RunReportPreRunCustomCode
    (in_report_oid IN NUMBER
    ,in_pageSize_nr IN INTEGER
    ,in_parameterList_tt IN parameterKeyValuePair_TT
    ,inout_reportRun_oid IN OUT NOCOPY NUMBER
    ,inout_error_yn IN OUT NOCOPY VARCHAR2
    ,inout_outputOption IN OUT NOCOPY VARCHAR2
    ,inout_reportOutPut_cl IN OUT NOCOPY NCLOB
    IS
    BEGIN
    NULL; -- Compiler shows this warning for this line: Warning(667,7): PLW-06002: Unreachable code
    -- dbms_output.put_line('x');
    END;
    It gets better! I removed the comment line and the warning stopped showing up. I put the comment line back in, and it hasn't come back (yet). I've seen this before.
    Removing the comment in this procedure also caused the same warning for another procedure to go away!
    The code in that procedure looked like this:
    BEGIN
    IF in_some_param IS NULL THEN
    NULL;-- Compiler shows this warning for this line: Warning(667,7): PLW-06002: Unreachable code
    ELSE
    ...

    Does compiling in SQL*Plus also produce the same behaviour? It should, since they both use the same compiler.
    I've just tested this in SQL*PLus. After setting the plsql_warnings to "enable:all" to match the default settings in sqldeveloper, the same warning is produced so it is a dbms issue, not sqldeveloper issue.
    Edited by: Jim Smith on Oct 11, 2008 4:01 PM

  • Unreachable code PLW 06002

    Hi All,
    Found this error unreachable code and the package did not add the data into test.
    Anything wrong here, My logic is a bit amateur, I apologize.
    IF (lv_countnew = 0)
          THEN
             RAISE lvexp_newrecords_notfound_err;
          IF (lv_countnew <> 0)
          THEN
             select count(*)
             into lv_countcsns
             from TEST;
          IF(lv_countcsns = 0)
          THEN
              send_error_report
              ('TEST is empty');
          IF(lv_countcsns <> 0)
          THEN
            insert into TEST
            (id_seq,id,sell,date)
            select id_seq,id,sell,sysdate
            from a_TEST
            where add_who ='IMPORT_test'
            and id not in (select distinct id from TEST);
          END IF;
    END IF;
    END IF;
      END IF;Thank you.

    IF (lv_countnew = 0)
    THEN
        RAISE lvexp_newrecords_notfound_err;
        IF (lv_countnew <> 0) THEN
            select count(*)
              into lv_countcsns
              from TEST;
            IF(lv_countcsns = 0) THEN
                send_error_report ('TEST is empty');
                IF(lv_countcsns <> 0) THEN
                    insert into TEST (id_seq,id,sell,date)
                    select id_seq,id,sell,sysdate
                    from a_TEST
                    where add_who ='IMPORT_test'
                    and id not in (select distinct id from TEST);
                END IF;
            END IF;
        END IF;
    END IF;As Dan pointed out:
    - if the topmost IF branch is true, the next line will raise an exception (lvexp_newrecords_notfound_err), due to which nothing will be inserted.
    - if the topmost IF branch is false, then the control will not reach that INSERT statement anyway.
    So, either way, you will never be able to insert your data.
    >
    What want irt to happen is...
    To ad dteh previous data if teh current data do not have it...
    Fro example:
    If the count of the table_A is not empty then proceed
    inserting data from table_B which are not in
    table_A.
    table A is present data
    table B is last week's dataSomething like this should help; customize it for your table structures.
    declare
      n_temp  number;
    begin
      select 1
      into n_temp
      from table_a
      where rownum = 1;
      -- table_a is not empty
      -- so proceed with the insert
      insert into table_a
      select * from table_b tb
      where tb.id not in (select ta.id
                            from table_a ta);
    end;
    /HTH
    isotope

  • Compiler not reporting unreachable code

    I had obvious bug code after return, but compiler did not
    even reported an error should not it flag it as unreachable code?)
    is that normal?

    It works as long as I delete all the class files each time, but that still doesn't explain why it's not recognizing the fact that it ought to recompile these classes every time. I've tried this on two different machines with two different operating systems, so it's not the environment. I've moved them, one file at a time, to brand new directories and the problem persists, so it's not any hidden files mucking things up. I don't even have a defined classpath. It has to be something intrinsic in these classes, and I'll be damned if I can figure out what.

  • Unreachable code detected using string in my master cs file

    can not string javascript or pages
    String javaScript =
    public
    String GetCurrentPageName()all
    the strings have the error.

    Hi Bumples ,
    Thanks for your posting.
    From your description, I can’t completely understand your issue: ” can’t  string javascript
    or pages “ ,” public String GetCurrentPageName() all the strings have the error”.
    Based on my understanding ,I need to confirm some information as follows:
    please let me that the detailed step to reproduce this issue .
    Please  offer us the master.cs file or
     a sample code  so that we can analyses this issue.
    Please let  me know that the detailed  information about error  or you can screenshot  in
    order that we can help you further.
    Hope these help.
    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

  • My compiler is executing unreachable code !

    Greetings
    I have an if - else statement such as :
    if (....)
    { for (...)
    ....return
    } // end if
    else {
    ... return
    } end else
    return something; // unreachableI'm executing a loop 10 times, and at 5, 6 and 7. the unreahable section is executed!
    My question is : when does this happens? and how to prevent it?
    knowing that removing the unreachable return statement will result in a missing return statement while compiling

    First of all I want to thank you ...
    ok here is my method
    public int getPoints(int i, int m, boolean [] wrong, int [] array, int  [] key, int correctPoints, int falsePoints)
       if (wrong [m-1] == false)
          for(int j = i; j < i + 4; j++)
             if (array[j] < 220 )
                if ( key[j] < 220)
                   return correctPoints;
               else
                   return falsePoints
    else
          return falsePoints;
    return -1; // shouldn't be reached I will try as BIJ001 did. that is eliminate the else. but I am still confused about the reason why -1 is returned.

  • Compiling Packages, Functions, and Procedures Issues

    If you are in the editor for a package and attempt to compile a know good package under another schema (compiled in SQL+ and Toad), you receive the following errors:
    Error(21,5): PLW-06002: Unreachable code
    Error(131,7): PLW-07202: bind type would result in conversion away from column type
    (122) TN_EXISTS NUMBER := 0;
    (131) IF TN_EXISTS > 0 THEN ...
    When commenting a line with if you have something like the following it tells you there is a syntax error
    -- some comment here --
    When compiling a PL/SQL function that returns a Boolean, you get this error: Error(40,4): PLW-06002: Unreachable code

    Kris,
    I seem to have the same problem.
    Is there a way to 'deactivate' this behaviour, or do we need to wait for another Raport Release.
    This is basically preventing me from using Raptor at all for any PL/SQL development ;-(
    Wouter

  • Eliminate warnings

    alter session set plsql_warnings = 'enable :all'
    alter session set succeeded.
    create or replace procedure scott as
    l_empno number(10):=7686;
    begin
    select empno into l_empno from emp where rownum = 1;
    if l_empno is not null then
    goto b;
    end if;
    <<b>>
    dbms_output.put_line('yahoo');
    end;
    my procedure successfully complied  with Warnings;
    i am getting tthe below warning.
    Warning(9,2): PLW-06002: Unreachable code.
    i want to eliminate the above warning without disable the  warning.

    i am getting tthe below warning.What database are you on?
    On my 11.2.0.2 I get just the usual "optional AUTHID" warning:
    SQL> alter session set plsql_warnings = 'enable :all'
    Session altered.
    SQL> select * from v$version where rownum = 1
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production         
    1 row selected.
    SQL> create or replace procedure scott
    as
      l_empno   number (10) := 7686;
    begin
      select empno
        into l_empno
        from emp
       where rownum = 1;
      if l_empno is not null
      then
        goto b;
      end if;
    <<b>>
      dbms_output.put_line ('yahoo');
    end scott;
    Procedure created.
    SQL> show err
    Errors for PROCEDURE SCOTT
    LINE/COL ERROR                                                           
    1/1      PLW-05018: unit SCOTT omitted optional AUTHID clause; default val
             ue DEFINER used                                                 
                                                                                   

  • Eliminate warings

    hi  i am working with SQL developer Tool,
    here i am some warings in my procedure.. but not errors.
    here my PM wants to eliminate those warings..
    how to do this issue..
    like below..
    Package body [email protected]...
    Warings(167,21): PLW-07204: conversion from column may result in sub-optimal plan
    Waring(1856,23): PLW-07202 bind type would result in conversion away column type

    The problem might be, that you cannot eliminate the warnings.
    E.g. if you have a package with many functions, each has an exception section where the error is logged and reraised without a RETURN. You won't see usefull warnings (Warning(1,1): Only first 20 issues are reported) for all those
    Warning(675,1): PLW-05005: function GETZAW returns without value at line 737Or if I get tons of
    Warning(1899,60): PLW-07204: conversion away from column type may result in sub-optimal query planin Selects like
    WHERE col1 = NVL(col2,col1)Or if you can't fix it because
    Warning(2134,17): PLW-06002: Unreachable codeshows a line that is reached regularily.
    I think compiler warnings are a good invention but they can be improved.
    Regards
    Marcus

  • Constant expression required

    (Original thread http://forum.java.sun.com/thread.jsp?forum=31&thread=428634)
    Hello all,
    in the following class, if the comment is removed, the compiler complains that a constant expression is required.
    class Test {
    final static int A;
    final static int B=5;
    static {
    A=5;
    public static void main(String args[]) {
    switch(1) {
    //case A:
    case B:
    Is this a bug? Is this a feature? How could A not be a constant expression?
    Is it good coding style to initialize constant variables at declaration time and not in the static block?
    7Kami

    (Original thread
    http://forum.java.sun.com/thread.jsp?forum=31&thread=42
    634)
    Hello all,
    in the following class, if the comment is removed, the
    compiler complains that a constant expression is
    required.
    class Test {
    final static int A;
    final static int B=5;
    static {
    A=5;
    public static void main(String args[]) {
    switch(1) {
    //case A:
    case B:
    Is this a bug? Is this a feature? How could A not be a
    constant expression?JLS goes to a lot of detail explaining why this is a language feature. It is required to support Java's requirement to never have unreachable code. In order to do that, the compiler need to have compile-time const expressions in case labels (otherwise it can never detect at static compilation time whether a case branch is reachable or not [e.g., because it clashes with another case label]). Those expressions could be either literals or static finals etc.
    This, BTW, explains why inlining of static finals is not just an optimization but an essential language requirement.
    The relevant JLS sections to read are 14.20 and 13.4.8.

  • Error while building an executable from vi

    Hello,
    I am trying to make a .exe file from the VI which includes Vision Aquisition Software also and while building it I get a error message--
    Error 1502 occurred at AB_Source_VI.lvclass:Close_Reference.vi -> AB_Build.lvclass: Save.vi -> AB_Build.lvclass:Copy_Files.vi -> AB_Application.lvclass:Copy_Files.vi -> AB_EXE.lvclass:Copy_Files.vi -> AB_Build.lvclass:Build.vi -> AB_Application.lvclass:Build.vi -> AB_EXE.lvclass:Build.vi -> AB_Build.lvclass:Build_from_Wizard.vi -> AB_UI_Frmwk_Build.lvclass:Build.vi -> AB_UI_FRAMEWORK.vi -> AB_Create_Build_Application.vi -> EBUIP_Global_OnCommand.vi -> EBUIP_Global_OnCommand.vi.ProxyCaller
    Possible reason(s):
    LabVIEW: Cannot save a bad VI without its block diagram.
    Can anyone tell me how to solve this problem ?
    Thanks in advance.

    I had done that and did not work.  I did not get rid of the old build defination, but started a brand new one via Tools>Build Application (EXE) from VI...  I got the same error 1502.  Inspecting the offending VI did not yield any obvious problem with the block diagram. 
    Upon searching for error 1502, I found this Know Issue link:
    http://www.ni.com/white-paper/11869/en.  Issue ID 255617 stated:
    Error 1502 can occur if dependencies are placed in non executing case structures
    In previous versions of LabVIEW you could place VIs in a case structure with a constant wired the the case selector. This would load the VIs at runtime. If you have this pattern and attempt to build an executable you could receive error 1502
    Workaround: Don't use unreachable code
    So the issue is I have an case structure with hard coded boolean, so the other case is unreachable.

  • Unable to edit old versioned file in KM

    Hi,
    I have a requirement wherein I need to edit older versioned file in KM programatically. I have got the older version file but I am not able to edit it and it gives an error; "*this collection does not support workspace creation".
    Supopse, I have versioning enabled on /documents/Public documents/test folder programatically. I created new version of a file say test.txt in it through code. This much is working fine. But, editing of older versioned file is creating problem. I used the below code:
    IVersionHistory iVersHistory = fileResource.getVersionHistory(); // fileResource refers to test.txt
    wdComponentAPI.getMessageManager().reportSuccess("IVersionHistory SIZE: " +iVersHistory.size());
    IResource resourceElement = null;
    name=fileResource.getName();
    IResource R1v5VCR=null;
    for(int i=0; i < iVersHistory.size(); i++)
      resourceElement = iVersHistory.get(i);
      list.add(resourceElement);
      if(resourceElement.getName().equalsIgnoreCase("test(3).txt"))
        //resourceElement.setAsCurrentVersion();
       ICollection collection = folder; // refers to /documents/Public documents/test folder
       wdComponentAPI.getMessageManager().reportSuccess("Reached "+collection.getRID());
       if( collection.isA(IExtendedCollection.class) )
         wdComponentAPI.getMessageManager().reportSuccess(" extending ");
         IExtendedCollection extendedCollection = (IExtendedCollection)collection.as(IExtendedCollection.class); 
         ICollection workspace = extendedCollection.createWorkspace("myworkspace", null); ---> Error on this line
         wdComponentAPI.getMessageManager().reportSuccess("Created test folder workspace ");
         IExtendedCollection Wa = (IExtendedCollection)workspace.createCollection("test",null).as(IExtendedCollection.class);
         R1v5VCR = Wa.createVersionControlledResource(resourceElement.getRID(), resourceElement.getName(),null);
         wdComponentAPI.getMessageManager().reportSuccess("Created New versioned resource ");
        // more code but unreachable code
    For editing a revision resource (i.e older version file), we have to create workspace on extendedCollection.
    I went through this URL: [http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/com.sap.km.cm.docs/library/netweaver/netweaver-developers-guide-2004s/NetWeaverDevelopersGuide2004s_Documents/KM_articles_new/howto/rf/client_api/rf_client_api_sdn.html|http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/com.sap.km.cm.docs/library/netweaver/netweaver-developers-guide-2004s/NetWeaverDevelopersGuide2004s_Documents/KM_articles_new/howto/rf/client_api/rf_client_api_sdn.html]
    Let me know if you have any solution or suggestion in this context.
    Thanks,
    Udit

    Hi Julian,
    Tjanks for the reply. But I already moved with that approach. I was finally able to create the workspace and a new versioned resource inside the workspace. But I get a new error on checkout of the resource: "subsequent checkin is expected to cause a fork!"
    Below is the code snippet used:
    IResource R1v5VCR=null;
    IResource resourceElement = iVersHistory.get(5); // file(5).txt is coming properly
    IResourceMetadata resourceMetadata=(IResourceMetadata)resource.as(IResourceMetadata.class);
    IRidSet ridSet=resourceMetadata.getWorkspaceCollectionSet();
    IRidIterator iter=ridSet.iterator();
    RID workRID=null;
    while(iter.hasNext()){
    workRID=iter.next();}
    ICollection newWorkSpace=(ICollection)ResourceFactory.getInstance().getResource(workRID,resourceContext);
    wdComponentAPI.getMessageManager().reportSuccess("Created folder workspace ");
    IExtendedCollection Wa =(IExtendedCollection)newWorkSpace.createCollection("test",null).as(IExtendedCollection.class);
    R1v5VCR = Wa.createVersionControlledResource(resourceElement.getRID(),resourceElement.getName(),null);
    R1v5VCR.checkOut(); --> Error on this line
    So, this issue is taking time now and I want to resolve it soon.
    Regards,
    Udit

  • Startup application doesn't start on cRIO (work fine on the target with LV RT)

    Hello!
    I have a application (running on a cRIO-9075) that is communicating with a GPS via RS-323 (using NI-9870).
    I can run the code without problems with LabVIEW RT on the target but when I build the executable and setting it up to run at startup it doesn't run.
    If I remove the GPS code, the startup application will run fine. As soon as I put back the GPS code, it will not... I see that looking at a Heartbeat shared variable (no heartbeat when the GPS code is there). Also, the startup application will not run if the GPS code is there even if that code is disabled...
    I have attached a screenshot of the code and one of the software installed on the cRIO for more clarity.
    I'm using LabVIEW 2011.
    Thanks in advance!
    Vincent
    Attachments:
    GPS Code.PNG ‏10 KB
    Software on cRIO.PNG ‏22 KB

    Hello,
    Sorry for the late response.
    I was able to make the application work for some time and for an unknown reason, it's not starting anymore. I made a change in the code and the problem is now back.
    The code still work as expected when launched using LabVIEW (arrow button).
    The output from the console is attached to this message, everything seems fine to me but maybe I'm missing something.
    I've looked at my code and I can't find any unreachable code (case structure or disable structure).
    I don't know if it might be related but I'm also getting the famous 1502 error (cannot save bad VI without block diagram) so I have to enable debugging to be able to build my application (which doesn't start afterwards).
    Any ideas?
    Thanks
    Vincent
    Attachments:
    App_NOT_Starting_Correctly.txt ‏3 KB

  • Minor inconsistency in javac prediction of branch

    Just curious why javac can predict branches when possible to determine if local variable is initialized but cannot do the same to determine if unreachable code exists:
    public void foo(){
         int x;
         if(true){
              x = 7;
         int p = x;
    }no problem here, javac can detect that the local variable x will be initialized every time and does not complain that x is not initialized when it is assigned to p. very good, javac.
    public void foo(){
         if(true){
              return;
         int x = 7;
    }in this case, javac fails to notice that the branch with the same condition will always execute, which leaves the int x=7 as unreachable code.
    So in the first code example, javac confidently believes the code will execute to remove the possibility of an uninialized variable being used; however, in the second code example, it believes there is a possibility that this same if branch will not be taken so the code that follows may be executed. This seems inconsistent.
    I'm not disappointed in this behavior, just surprised and wondering if there is a reason for it.

    in this case, javac fails to notice that the branch
    with the same condition will always execute, which
    leaves the int x=7 as unreachable code. It's probably not malicious or deliberate - just a condition that the compiler implementor forgot to check. And it's not a required check according to the language semantics either - you just lucked out in one case, and didn't in the other.
    Send in a bug report/enhancement request for consideration in a future release..

Maybe you are looking for