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 267282 - Pasting code with imports corrupts imports in target file
Summary: Pasting code with imports corrupts imports in target file
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-24 17:24 UTC by mclaborn
Modified: 2017-06-30 15:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (76.07 KB, text/plain)
2016-07-24 17:24 UTC, mclaborn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mclaborn 2016-07-24 17:24:11 UTC
Product Version = NetBeans IDE Dev (Build 201607210002)
Operating System = Linux version 4.4.0-31-generic running on amd64
Java; VM; Vendor = 1.8.0_102
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.102-b14

Reproducibility: Happens sometimes, but not always

Pasting Java code that will also need some new imports sometimes corrupts the imports in the target file. 

For example, pasting the following code block:

      // create and send a new one
      Message l_msg = new MimeMessage(l_session_out);
      
      // from is a list
      Address[] l_from = l_old_msg.getFrom();
      if (l_from != null && l_from.length > 0) {
        l_msg.setFrom(l_from[0]);
      }
      
      l_msg.setReplyTo(l_old_msg.getReplyTo());
      l_msg.addRecipient(Message.RecipientType.TO, new InternetAddress(a_redirect_to));
      l_msg.setSubject(l_old_msg.getSubject());
      l_msg.setSentDate(l_old_msg.getSentDate());
      
      // now the parts
      Object l_content = l_old_msg.getContent();
      if (l_content == null) {
        l_return = "Message has no content??!!";
      } else if (l_content instanceof Multipart) {
        Multipart l_mp_old = (Multipart) l_content;
        l_msg.setContent(l_mp_old);
      } else if (l_content instanceof String) {
        String l_old_type = l_old_msg.getContentType();
        if (StringUtil.isEmpty(l_old_type)) {
          l_old_type = "text/plain";
        }
        l_msg.setContent(l_content, l_old_type);
      } else {
        l_return = "Don't know how to deal with content type " + l_content.getClass().getName();
      }
      
      if (l_return == null) {
        Transport.send(l_msg);
      }


Resulted in this:

import javax.mail.Multipart;
import javax.mail.Message;
import javax.mail.PasswordAuthenticatiimport javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
on;
import javax.mail.Session;
import javax.mail.Store;


I can typically recover by deleting the corrupted import lines and doing "fix imports".
Comment 1 mclaborn 2016-07-24 17:24:14 UTC
Created attachment 161406 [details]
IDE log
Comment 2 Svata Dedic 2016-08-04 15:18:48 UTC
I need to debug the issue with the exact file (perhaps some positioning screws up).

When the issue happens again, please try the following: 
1/ Undo to the point before code block paste.
2/ Save the file, close editor
3/ Open file again, do the paste
4/ Check imports; if they are screwed again, great ! Close the editor (do not save contents) and send me the exact file or attach the file here. Also export *all* your options (Tools | Options > Export button). 
5/ if the file does not become corrupted, bad luck :-/ try again.