Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 206193 - [71cat] malfunction of extract method if duplicate code exists
[71cat] malfunction of extract method if duplicate code exists
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Hints
7.1
PC Windows XP
: P3 (vote)
: 7.2
Assigned To: Jan Lahoda
issues@java
71patch-candidate
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-09 13:52 UTC by muellermi
Modified: 2012-04-26 10:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description muellermi 2011-12-09 13:52:41 UTC
Product Version = NetBeans IDE 7.1 (Build 201112051121)
Operating System = Windows XP version 5.1 running on x86
Java; VM; Vendor = 1.7.0_01
Runtime = Java HotSpot(TM) Client VM 21.1-b02

given this portion of code:
method1:
[...]
        try {
            FileInputStream fis = new FileInputStream(encryptedFile);
            Pair<Integer, byte[]> versionAndKey = readHeader(fis);
(x)            SecretKeySpec key = new SecretKeySpec(rsaDecrypt(versionAndKey.getValue2()), "AES");
(x)            Cipher cipher = Cipher.getInstance("AES");
(x)            cipher.init(Cipher.DECRYPT_MODE, key);
            decryptStream(fis, cipher, new File(decryptedFile));
[...]

method2:
[...]
        try {
            FileInputStream fis = new FileInputStream(encryptedFile);
            Pair<Integer, byte[]> versionAndKey = readHeader(fis);
(x)           SecretKeySpec key = new SecretKeySpec(rsaDecrypt(versionAndKey.getValue2()), "AES");
(x)            Cipher cipher = Cipher.getInstance("AES");
(x)            cipher.init(Cipher.DECRYPT_MODE, key);
            if (versionAndKey.getValue1() != 2) {
[...]

- In method1, mark the lines indicated with (x)
- Press Alt-Shift-m
- name new Method getCipher
--> NB asks whether you would replace the duplicate code of method2 too
- answer yes
--> in method1 these three lines are replaced by
            Cipher cipher = getCipher(versionAndKey);
whilst in method2 it is
            Cipher cipher;

### Method call is missing. ###




--------------------------------------------------------------------------------------------------------------------------
BTW:

The automatic introduced method is

    private Cipher getCipher(Pair<Integer, byte[]> versionAndKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
        SecretKeySpec key = new SecretKeySpec(rsaDecrypt(versionAndKey.getValue2()), "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        return cipher;
    }

SecretKeySpec needs an array of byte, versionAndKey.getValue2() is the one. Thus refactoring might better result in

    private Cipher getCipher(byte[]> value2) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException {
        SecretKeySpec key = new SecretKeySpec(rsaDecrypt(value2()), "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        return cipher;
    }

whereas value2  is a derived variable name. Is this feasable?
If the refactoring works like this, the developer only needs to change this ugly name.
Comment 1 Jiri Prox 2011-12-12 12:34:41 UTC
reproducible
Comment 2 Jan Lahoda 2012-04-23 13:34:47 UTC
Fixed in NetBeans daily builds, thanks for the report:
http://hg.netbeans.org/jet-main/rev/8b5a083160a0
Comment 3 Quality Engineering 2012-04-26 10:35:53 UTC
Integrated into 'main-golden', will be available in build *201204260400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/8b5a083160a0
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #206193: introduce method sometimes forgets to invoke the newly created method due to a flag clash - adding a new flag to keep track if the method was or was not already invoked.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo