This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 199335 - Introduce Method didn't work correctly
Summary: Introduce Method didn't work correctly
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.0
Hardware: PC Other
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-10 09:48 UTC by tomzi
Modified: 2011-06-15 14:10 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tomzi 2011-06-10 09:48:00 UTC
I have following codesegment. 

            preparedStat = dbConnection.prepareStatement(sqlQuery);
            int index = 1;
            for (Object sqlParam : sqlParams) {
                if (sqlParam instanceof String) {
                    preparedStat.setString(index, (String) sqlParam);
                } else if (sqlParam instanceof Date) {
                    preparedStat.setTimestamp(index, new Timestamp(((Date)sqlParam).getTime()));
                } else if (sqlParam instanceof Timestamp) {
                    preparedStat.setTimestamp(index, (Timestamp)sqlParam);
                } else if (sqlParam instanceof BigDecimal) {
                    preparedStat.setBigDecimal(index, (BigDecimal)sqlParam);
                } else if (sqlParam instanceof Boolean) {
                    preparedStat.setBoolean(index, (Boolean)sqlParam);
                } else if (sqlParam instanceof Double) {
                    preparedStat.setDouble(index, (Double)sqlParam);
                } else if (sqlParam instanceof Float) {
                    preparedStat.setFloat(index, (Float)sqlParam);
                } else if (sqlParam instanceof Integer) {
                    preparedStat.setInt(index, (Integer)sqlParam);
                } else if (sqlParam instanceof Long) {
                    preparedStat.setLong(index, (Long)sqlParam);
                } else if (sqlParam == null) {
                    preparedStat.setNull(index, Types.NULL);
                } 
                index++;
            }

I wanted to extract the inner part of the for loop and following was extracted:
...
            preparedStat = dbConnection.prepareStatement(sqlQuery);
            int index = 1;
            for (Object sqlParam : sqlParams) {
                setDbParam(preparedStat, index);
                index++;
            }
...

    private void setDbParam(PreparedStatement preparedStat, int index) throws SQLException {
        Object sqlParam;
        if (sqlParam instanceof String) {
            preparedStat.setString(index, (String) sqlParam);
        } else if (sqlParam instanceof Date) {
            preparedStat.setTimestamp(index, new Timestamp(((Date)sqlParam).getTime()));
        } else if (sqlParam instanceof Timestamp) {
            preparedStat.setTimestamp(index, (Timestamp)sqlParam);
        } else if (sqlParam instanceof BigDecimal) {
            preparedStat.setBigDecimal(index, (BigDecimal)sqlParam);
        } else if (sqlParam instanceof Boolean) {
            preparedStat.setBoolean(index, (Boolean)sqlParam);
        } else if (sqlParam instanceof Double) {
            preparedStat.setDouble(index, (Double)sqlParam);
        } else if (sqlParam instanceof Float) {
            preparedStat.setFloat(index, (Float)sqlParam);
        } else if (sqlParam instanceof Integer) {
            preparedStat.setInt(index, (Integer)sqlParam);
        } else if (sqlParam instanceof Long) {
            preparedStat.setLong(index, (Long)sqlParam);
        } else if (sqlParam == null) {
            preparedStat.setNull(index, Types.NULL);
        }
    }

Obviously the ide did NOT detect sqlParam as a parameter for the setDbParam method, which it should have.


Product Version: NetBeans IDE Dev (Build 201106041000)
Java: 1.6.0_25; Java HotSpot(TM) 64-Bit Server VM 20.0-b11
System: Windows 7 version 6.1 running on amd64; Cp1252; de_AT (nb)
Userdir: C:\Users\thomas.zillinger\.netbeans\dev
Comment 1 Jan Lahoda 2011-06-14 17:15:34 UTC
Thanks for the testcase. Fixed in trunk by:
http://hg.netbeans.org/jet-main/rev/e50868ad7957
and in release701 by:
http://hg.netbeans.org/releases/rev/09f8a756d359
Comment 2 Quality Engineering 2011-06-15 04:41:28 UTC
Integrated into 'releases'
Changeset: http://hg.netbeans.org/releases/rev/09f8a756d359
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #199335: need to scan the enhanced for loop variable too.
Comment 3 Quality Engineering 2011-06-15 14:10:36 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/e50868ad7957
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #199335: need to scan the enhanced for loop variable too.