Results 1 to 12 of 12
  1. #1
    ancr2001 is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Decompiling java class files

    I have a java class file that I decompiled. I changed some embedded SQL code and now it won't compile. I got a lot of java import errors, which I fixed, but I still have a problem with a Syntax error, insert "AssignmentOperator Expression" to complete Expression. I haven't even changed any java code and this class file was working before I decompiled it. Here is a snippet:
    public void updateDebtAccountQLevels()
    {
    String updateQLevels;
    PreparedStatement pstmt;
    ResultSet rs;
    int qLevelCount;
    updateQLevels = (new StringBuilder(" SQL stuff here)).append(AD_Client_ID).toString();
    pstmt = null;
    rs = null;
    qLevelCount = 0;
    try
    {
    pstmt = DB.prepareStatement(updateQLevels, null);
    for(rs = pstmt.executeQuery(); rs.next();)
    {
    int differenceDate = DateUtil.calculateDifference(new Timestamp(System.currentTimeMillis()), rs.getTimestamp("um_datereceived"));
    String queueLevel = rs.getString("UM_QueueLevel");
    String statusCode = rs.getString("um_statuscode");
    int debtAccountID = rs.getInt("um_debtaccount_id");
    if(differenceDate < 31)
    queueLevel = "020";
    else
    if(differenceDate > 30 && differenceDate < 61)
    queueLevel = "030";
    else
    if(differenceDate > 60 && differenceDate < 91)
    queueLevel = "060";
    else
    if(differenceDate > 90 && differenceDate < 121)
    queueLevel = "090";
    else
    if(differenceDate > 120)
    queueLevel = "100";
    if("DUP".equals(statusCode))
    queueLevel = "875";
    if("010".equals(rs.getString("UM_QueueLevel")))
    queueLevel = "010";
    String updateQLevelQuery = (SQL stuff in here).toString();
    updateQuery(updateQLevelQuery);
    qLevelCount++;
    }


    }
    catch(Exception e)
    {
    e.printStackTrace();
    break MISSING_BLOCK_LABEL_319;
    }
    break MISSING_BLOCK_LABEL_311;
    Exception exception;
    exception; // I get the error here. If I comment out the error I get unhandled exception type @ the throw two lines down
    DB.close(rs, pstmt); // If I comment out @ Exception exception I get an unreachable code error at this line.
    throw exception;
    DB.close(rs, pstmt);
    break MISSING_BLOCK_LABEL_324;
    DB.close(rs, pstmt);
    log.severe((new StringBuilder("Queue Level Update count :")).append(qLevelCount).toString());
    System.out.println((new StringBuilder("Queue Level Update count :")).append(qLevelCount).toString());
    return;
    }

    I didn't write this code so I have no idea what's going on here. At first I thought that the single exception was a typo. How did this ever run in the first place?

    Another error I keep getting is duplicate local variable in this code:

    protected String endOfDayFinished()
    {
    String toUserMail;
    MClient fromClient;
    String fromUserMail;
    String fromUserMailPassword;
    String smtpHost;
    EMailAuthenticator m_auth;
    Properties props;
    String m_sentMsg = null;
    int p_AD_User_ID = 100;
    MUser user = new MUser(Env.getCtx(), p_AD_User_ID, null);
    toUserMail = client.getRequestEMail();
    int ad_client_id = user.getAD_Client_ID();
    fromClient = new MClient(Env.getCtx(), ad_client_id, null);
    fromUserMail = fromClient.getRequestUser();
    fromUserMailPassword = SecureEngine.decrypt(fromClient.getRequestUserPW() );
    smtpHost = fromClient.getSMTPHost();
    Session session = null;
    m_auth = null;
    props = new Properties();
    if(!fromClient.isSmtpAuthorization())
    break MISSING_BLOCK_LABEL_192;
    if(fromUserMail != null && fromUserMailPassword != null)
    break MISSING_BLOCK_LABEL_147;
    log.warning((new StringBuilder("Ignored - ")).append(fromUserMail).append("/").append(fromUserMailPassword).toString());
    m_auth = null;
    return "Request User Mail/Password should not be null, Check in Company screen";
    if(smtpHost == null)
    return "Mail Host should not be null, Check in Company screen";
    if(toUserMail == null || toUserMail.equals(""))
    return "Invalid 'To User' mail, Check in System User";
    //Session session;
    try
    {
    m_auth = new EMailAuthenticator(fromUserMail, fromUserMailPassword);
    }
    catch(SecurityException se)
    {
    log.log(Level.WARNING, (new StringBuilder("Auth=")).append(m_auth).append(" - ").append(se.toString()).toString());
    m_sentMsg = se.toString();
    return se.toString();
    }
    catch(Exception e)
    {
    log.log(Level.SEVERE, (new StringBuilder("Auth=")).append(m_auth).toString(), e);
    m_sentMsg = e.toString();
    return e.toString();
    }
    break MISSING_BLOCK_LABEL_196;
    return "SMTP Authentication must be checked, Check in System Client";
    if(m_auth != null)
    props.put("mail.smtp.auth", "true");
    session = Session.getInstance(props, m_auth);
    session.setDebug(CLogMgt.isLevelFinest());
    Session m_sentMsg; // I get the error here. Obviously, Session m_sentMsg is declared at the beginning of the
    try // class and set to null
    { // so I commented it out as another possible typo. However it breaks the if statement at

    // MISSING_BLOCK_LABEL_### with an error saying its label is missing.

    I'm clueless???!!!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: Decompiling java class files

    Post the full text of the error messages.

    Please edit the post and add code tags around the code to preserve the code's formatting.
    BB Code List - Java Programming Forum
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Decompiling java class files

    Did you ever take a look at the code? I mean from an understanding point of view and not from the 'trial and error' point of view? ;)
    You will see immediately that this like it is now, is not really a working java code at the location you marked in the code.
    I like likes!

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Decompiling java class files

    Don't forget, to recompile, you will need all referenced classes and packages in the code to be available in the classpath - this can make it quite tricky to do what you're trying to do! Also, decompiling can sometimes produce code that is quite different than the original code - making recompiling more difficult.

  5. #5
    ancr2001 is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Decompiling java class files

    Java Code:
    package org.compiere.eod;
    
    
    
    import java.io.FileInputStream;
    import java.io.PrintStream;
    import java.math.BigDecimal;
    import java.sql.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.logging.Handler;
    import java.util.logging.Level;
    import javax.mail.*;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import org.compiere.Adempiere;
    import org.compiere.model.*;
    import org.compiere.service.cws.CWSAppService;
    import org.compiere.util.*;
    import java.util.Date;
    import java.lang.StringBuilder;
    import java.lang.Object;
    import java.lang.Throwable;
    import javax.mail.Session;
    import java.lang.Exception;
    import java.lang.Error;
    
    
    
    public class EndOfDayProcess
    {
        public EndOfDayProcess()
        {
            count = 0;
            log = CLogger.getCLogger(getClass());
            eod = null;
        }
    
        public static void main(String args[])
        {
            EndOfDayProcess eod = new EndOfDayProcess();
            eod.initiateEndOfDay(args);
        }
    
    
    public void updateDebtAccountQLevels()
        {
            String updateQLevels;
            PreparedStatement pstmt;
            ResultSet rs;
            int qLevelCount;
            updateQLevels = (new StringBuilder(" SQL stuff here)).append(AD_Client_ID).toString();
            pstmt = null;
            rs = null;
            qLevelCount = 0;
            try
            {
                pstmt = DB.prepareStatement(updateQLevels, null);
                for(rs = pstmt.executeQuery(); rs.next();)
                {
                    int differenceDate = DateUtil.calculateDifference(new Timestamp(System.currentTimeMillis()), rs.getTimestamp("um_datereceived"));
                    String queueLevel = rs.getString("UM_QueueLevel");
                    String statusCode = rs.getString("um_statuscode");
                    int debtAccountID = rs.getInt("um_debtaccount_id");
                    if(differenceDate < 31)
                        queueLevel = "020";
                    else
                    if(differenceDate > 30 && differenceDate < 61)
                        queueLevel = "030";
                    else
                    if(differenceDate > 60 && differenceDate < 91)
                        queueLevel = "060";
                    else
                    if(differenceDate > 90 && differenceDate < 121)
                        queueLevel = "090";
                    else
                    if(differenceDate > 120)
                        queueLevel = "100";
                    if("DUP".equals(statusCode))
                        queueLevel = "875";
                    if("010".equals(rs.getString("UM_QueueLevel")))
                        queueLevel = "010";
                    String updateQLevelQuery = (SQL stuff in here).toString();
                    updateQuery(updateQLevelQuery);
                    qLevelCount++;
                }
    
            }
            catch(Exception e)
            {
                e.printStackTrace();
                break MISSING_BLOCK_LABEL_319;
            }
            break MISSING_BLOCK_LABEL_311;
            Exception exception;
            exception;
            DB.close(rs, pstmt);
            throw exception;
            DB.close(rs, pstmt);
            break MISSING_BLOCK_LABEL_324;
            DB.close(rs, pstmt);
            log.severe((new StringBuilder("Queue Level Update count :")).append(qLevelCount).toString());
            System.out.println((new StringBuilder("Queue Level Update count :")).append(qLevelCount).toString());
            return;
        }
    I apologize for the mess. Here is the forum accepted format. This is just one of the classes from the main class. I know this won't run by itself. The error is at line 95 and 96. I have several other classes in the main class that have the same exception error. From what I know about exceptions this code looks unfamiliar and confusing. I tried importing the java.lang.Exception but it changes nothing. Is there an Exception class I'm not referencing? The error I get on all four instances of these exception errors is:Syntax error, insert "AssignmentOperator Expression" to complete Expression. I'm very rusty on my programming skills so bear with me.

  6. #6
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Decompiling java class files

    You should give the line where your errors happen, if you want a quick answer...
    I mean you say you know it won't run and complain about errors? Yes there will be lots of them... e.g.:

    Java Code:
    Exception exception;
    exception; // I get the error here. If I comment out the error I get unhandled exception type @ the throw two lines down
    ...
    throw exception;
    .... what should a blank "exception" in a line mean to anyone? OF course you get errors there... and of course the code after throw exception is unreachable because before you reach the end you throw an exception...? ;)
    Last edited by Sierra; 05-14-2012 at 08:24 PM.
    I like likes!

  7. #7
    ancr2001 is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Decompiling java class files

    I put this in TextPad and it said exception was a reserved word indicating Java class. I've imported that class already. About the blank exception, what do you suggest I do? If I remove or comment it out I get new errors. In eclipse shouldn't it turn the lower case exception blue and italicized? It does it in other instances but seems to be picky. Again this is just a sub class of a main class and I didn't write any of this code. Could the decompiler have generated these errors as suggested by quad64bit? While searching google I came across some forum posts that said JVM doesn't recognize inner classes and has to make up code when going through the loops during decompile.
    Last edited by ancr2001; 05-14-2012 at 10:11 PM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Decompiling java class files

    'exception' isn't a reserved word, so I doubt thats a problem. Forget about what TextPad says, what does the compiler say?

    ANyway, decompiling and recompiling (as has been said above) is notoriously unreliable.
    Get hold of the original source code and modify that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Decompiling java class files

    In any development environment the syntax highlighting is unreliable if too many errors are there. Do not take this as god-given. Also the software has difficulties with such buggy code.

    Sorry to say so but: If you say you get more errors when commenting it out it shows me that you do not have the skills to decompile and understand the code yet. There are three ways:
    - Go through the program and try to understand every single line of code and what it does and correct it (that is why decompiling is not as easy as it might seem to a beginner)
    - Write your own code using code snippets from the decompiled program and hope to understand what it does
    - Do as Tolls said - which is what I would suggest to you

    In general errors are caused by wrong code:
    If you not correct it they will stay there. To correct them you have to understand what the code is intended to do. To understand non-working code, you usually need advanced knowledge of the programming language.
    I like likes!

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,733
    Blog Entries
    7
    Rep Power
    21

    Default Re: Decompiling java class files

    My guess is that the code is incorrectly decompiled; disassemble the code using javap and see what the code really is.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    ancr2001 is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Decompiling java class files

    [SOLVED] Thanks everyone for your help! The problem was with the code DJ Compiler was putting out. I used the JD-GUI tool and it correctly decompiled the source code. I may be rusty but I though the exception blocks looked peculiar, which is why they had errors. The new code properly built the exceptions.

    -Mike-

  12. #12
    ancr2001 is offline Member
    Join Date
    May 2012
    Posts
    5
    Rep Power
    0

    Default Re: Decompiling java class files

    I would mark this thread as [Solved] but I can't seem to figure out where to do that.

Similar Threads

  1. Need help to compile java files to class
    By Candesco in forum New To Java
    Replies: 13
    Last Post: 12-24-2011, 08:24 PM
  2. How can i encrypt java class files
    By synclenovo in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2009, 08:08 AM
  3. Java Decompiling Help
    By RyanOLP in forum New To Java
    Replies: 1
    Last Post: 11-27-2008, 05:39 AM
  4. conversion of java .class files to .java files
    By kotturupraveen in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 01:58 PM
  5. Replies: 2
    Last Post: 12-04-2007, 11:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •