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 204638 - Move Inner to Outer Level corrupts class
Summary: Move Inner to Outer Level corrupts class
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.1
Hardware: PC Windows 7
: P1 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-03 15:59 UTC by _ gtzabari
Modified: 2011-12-07 14:43 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Testcase (3.94 KB, application/zip)
2011-11-04 14:45 UTC, _ gtzabari
Details

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2011-11-03 15:59:23 UTC
Product Version: NetBeans IDE Dev (Build 201110310600)
Java: 1.7.0; Java HotSpot(TM) Client VM 21.0-b17
System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb)
User directory: C:\Users\g.tzabari\.netbeans\dev
Cache directory: C:\Users\g.tzabari\.netbeans\dev\var\cache

1. Given:

public static class NativeLibraries
	{
		private static final Field loadedLibraryNames;
		private static final Field systemNativeLibraries;
		private static final Field nativeLibraries;
		private static final Field nativeLibraryFromClass;
		private static final Field nativeLibraryName;

		static
		{
			Field temp;
			try
			{
				temp = ClassLoader.class.getDeclaredField("loadedLibraryNames");
				if (temp != null)
					temp.setAccessible(true);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				temp = null;
			}
			loadedLibraryNames = temp;

			try
			{
				temp = ClassLoader.class.getDeclaredField("systemNativeLibraries");
				if (temp != null)
					temp.setAccessible(true);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				temp = null;
			}
			systemNativeLibraries = temp;

			try
			{
				temp = ClassLoader.class.getDeclaredField("nativeLibraries");
				if (temp != null)
					temp.setAccessible(true);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				temp = null;
			}
			nativeLibraries = temp;

			Class<?> nativeLibrary = null;
			for (Class<?> nested : ClassLoader.class.getDeclaredClasses())
			{
				if (nested.getSimpleName().equals("NativeLibrary"))
				{
					nativeLibrary = nested;
					break;
				}
			}
			try
			{
				temp = nativeLibrary.getDeclaredField("fromClass");
				if (temp != null)
					temp.setAccessible(true);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				temp = null;
			}
			nativeLibraryFromClass = temp;

			try
			{
				temp = nativeLibrary.getDeclaredField("name");
				if (temp != null)
					temp.setAccessible(true);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				temp = null;
			}
			nativeLibraryName = temp;
		}

		public static String[] getLoadedLibraries()
		{
			try
			{
				@SuppressWarnings("UseOfObsoleteCollectionType")
				final Vector<String> libraries = (Vector<String>) loadedLibraryNames.get(null);
				return libraries.toArray(new String[0]);
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				return null;
			}
		}

		/**
		 * Returns the native libraries loaded by the system class loader.
		 * <p/>
		 * @return a Map from the names of native libraries to the classes that loaded them
		 */
		public static Map<String, Class<?>> getSystemNativeLibraries()
		{
			try
			{
				@SuppressWarnings("UseOfObsoleteCollectionType")
				Map<String, Class<?>> result = new HashMap<>();
				final Vector<Object> libraries = (Vector<Object>) systemNativeLibraries.get(null);
				for (Object nativeLibrary : libraries)
				{
					String libraryName = (String) nativeLibraryName.get(nativeLibrary);
					Class<?> fromClass = (Class<?>) nativeLibraryFromClass.get(nativeLibrary);
					result.put(libraryName, fromClass);
				}
				return result;
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				return null;
			}
		}

		/**
		 * Returns a Map from the names of native libraries to the classes that loaded them.
		 * <p/>
		 * @param loader the ClassLoader that loaded the libraries
		 * @return an empty Map if no native libraries were loaded
		 */
		public static Map<String, Class<?>> getNativeLibraries(final ClassLoader loader)
		{
			try
			{
				@SuppressWarnings("UseOfObsoleteCollectionType")
				Map<String, Class<?>> result = new HashMap<>();
				final Vector<Object> libraries = (Vector<Object>) nativeLibraries.get(loader);
				for (Object nativeLibrary : libraries)
				{
					String libraryName = (String) nativeLibraryName.get(nativeLibrary);
					Class<?> fromClass = (Class<?>) nativeLibraryFromClass.get(nativeLibrary);
					result.put(libraryName, fromClass);
				}
				return result;
			}
			catch (ReflectiveOperationException e)
			{
				e.printStackTrace();
				return null;
			}
		}
		
		public static List<ClassLoader> getClassLoaders(ClassLoader loader)
		{
			List<ClassLoader> result = new ArrayList<>();
			ClassLoader parent = loader.getParent();
			result.add(loader);
			while (parent != null)
			{
				result.add(parent);
				parent = parent.getParent();
			}
			return result;
		}

		/**
		 * Returns a Map from the names of native libraries to the classes that loaded them.
		 * <p/>
		 * @param loader the ClassLoader that loaded the libraries
		 * @return an empty Map if no native libraries were loaded
		 */
		public static Map<String, Class<?>> getNativeLibrariesRecursive(final ClassLoader loader)
		{
			@SuppressWarnings("UseOfObsoleteCollectionType")
			Map<String, Class<?>> result = new HashMap<>();
			ClassLoader parent = loader.getParent();
			while (parent != null)
			{
				result.putAll(getNativeLibrariesRecursive(parent));
				parent = parent.getParent();
			}
			result.putAll(getNativeLibraries(loader));
			return result;
		}
	}

2. Refactor -> Move Inner to Outer Level -> OK
3. Resulting class is mangled:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
packpackcom.muxlab.vitex.server.launchercher;

import java.lang.reflect.Field;
import java.util.*;

/**
 *
 * @author g.tzabari
 */
NativeLibraries/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
	private static final Field loadedLibraryNames;
	private static final Field systemNativeLibraries;
	private static final Field nativeLibraries;
	private static final Field nativeLibraryFromClass;
	private static final Field nativeLibraryName;
	static
	{
		Field temp;
		try
		{
			temp = ClassLoader.class.getDeclaredField("loadedLibraryNames");
			if (temp != null)
				temp.setAccessible(true);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			temp = null;
		}
		loadedLibraryNames = temp;
		try
		{
			temp = ClassLoader.class.getDeclaredField("systemNativeLibraries");
			if (temp != null)
				temp.setAccessible(true);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			temp = null;
		}
		systemNativeLibraries = temp;
		try
		{
			temp = ClassLoader.class.getDeclaredField("nativeLibraries");
			if (temp != null)
				temp.setAccessible(true);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			temp = null;
		}
		nativeLibraries = temp;
		Class<?> nativeLibrary = null;
		for (Class<?> nested : ClassLoader.class.getDeclaredClasses())
		{
			if (nested.getSimpleName().equals("NativeLibrary"))
			{
				nativeLibrary = nested;
				break;
			}
		}
		try
		{
			temp = nativeLibrary.getDeclaredField("fromClass");
			if (temp != null)
				temp.setAccessible(true);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			temp = null;
		}
		nativeLibraryFromClass = temp;
		try
		{
			temp = nativeLibrary.getDeclaredField("name");
			if (temp != null)
				temp.setAccessible(true);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			temp = null;
		}
		nativeLibraryName = temp;
	}

	public static String[] getLoadedLibraries()
	{
		try
		{
			@SuppressWarnings(value = "UseOfObsoleteCollectionType")
			final Vector<String> libraries =
				(Vector<String>) loadedLibraryNames.get(null);
			return libraries.toArray(new String[0]);
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Returns the native libraries loaded by the system class loader.
	 * <p/>
	 * @return a Map from the names of native libraries to the classes that loaded them
	 */
	/**
	 * Returns the native libraries loaded by the system class loader.
	 * <p/>
	 * @return a Map from the names of native libraries to the classes that loaded them
	 */
	public static Map<String, Class<?>> getSystemNativeLibraries()
	{
		try
		{
			@SuppressWarnings(value = "UseOfObsoleteCollectionType")
			Map<String, Class<?>> result =
				new HashMap<>();
			final Vector<Object> libraries =
				(Vector<Object>) systemNativeLibraries.get(null);
			for (Object nativeLibrary : libraries)
			{
				String libraryName = (String) nativeLibraryName.get(nativeLibrary);
				Class<?> fromClass = (Class<?>) nativeLibraryFromClass.get(nativeLibrary);
				result.put(libraryName, fromClass);
			}
			return result;
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Returns a Map from the names of native libraries to the classes that loaded them.
	 * <p/>
	 * @param loader the ClassLoader that loaded the libraries
	 * @return an empty Map if no native libraries were loaded
	 */
	/**
	 * Returns a Map from the names of native libraries to the classes that loaded them.
	 * <p/>
	 * @param loader the ClassLoader that loaded the libraries
	 * @return an empty Map if no native libraries were loaded
	 */
	public static Map<String, Class<?>> getNativeLibraries(final ClassLoader loader)
	{
		try
		{
			@SuppressWarnings(value = "UseOfObsoleteCollectionType")
			Map<String, Class<?>> result =
				new HashMap<>();
			final Vector<Object> libraries =
				(Vector<Object>) nativeLibraries.get(loader);
			for (Object nativeLibrary : libraries)
			{
				String libraryName = (String) nativeLibraryName.get(nativeLibrary);
				Class<?> fromClass = (Class<?>) nativeLibraryFromClass.get(nativeLibrary);
				result.put(libraryName, fromClass);
			}
			return result;
		}
		catch (ReflectiveOperationException e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static List<ClassLoader> getClassLoaders(ClassLoader loader)
	{
		List<ClassLoader> result = new ArrayList<>();
		ClassLoader parent = loader.getParent();
		result.add(loader);
		while (parent != null)
		{
			result.add(parent);
			parent = parent.getParent();
		}
		return result;
	}

	/**
	 * Returns a Map from the names of native libraries to the classes that loaded them.
	 * <p/>
	 * @param loader the ClassLoader that loaded the libraries
	 * @return an empty Map if no native libraries were loaded
	 */
	/**
	 * Returns a Map from the names of native libraries to the classes that loaded them.
	 * <p/>
	 * @param loader the ClassLoader that loaded the libraries
	 * @return an empty Map if no native libraries were loaded
	 */
	public static Map<String, Class<?>> getNativeLibrariesRecursive(final ClassLoader loader)
	{
		@SuppressWarnings(value = "UseOfObsoleteCollectionType")
		Map<String, Class<?>> result = new HashMap<>();
		ClassLoader parent = loader.getParent();
		while (parent != null)
		{
			result.putAll(getNativeLibrariesRecursive(parent));
			parent = parent.getParent();
		}
		result.putAll(getNativeLibraries(loader));
		return result;
	}
age com.muxlab.vitex.server.launcher;

/**
 *
 * @author g.tzabari
 */
public class Class {
    
}
Comment 1 Jan Becicka 2011-11-03 16:48:19 UTC
generator issue I guess
Comment 2 Jan Becicka 2011-11-04 07:34:56 UTC
Anyway is it reproducible?
I'm on JDK 6 (JDK 7 is not yet final on Mac) and I cannot reproduce it.
This is JDK 7 source.
Comment 3 Ralph Ruijs 2011-11-04 08:50:01 UTC
(In reply to comment #2)
> Anyway is it reproducible?
> I'm on JDK 6 (JDK 7 is not yet final on Mac) and I cannot reproduce it.
> This is JDK 7 source.

Works for me on:

NetBeans IDE Dev (Build 20111103-75371828b598)(#75371828b598)
Linux version 2.6.38-gentoo-r6 running on amd64
1.7.0_147-icedtea; OpenJDK 64-Bit Server VM 21.0-b17; Oracle Corporation
OpenJDK Runtime Environment 1.7.0_147-icedtea-b147
Comment 4 Jan Lahoda 2011-11-04 09:30:20 UTC
I tried several times to reproduce manually, and in the unit tests. Unfortunately, I cannot reproduce this. Sorry, but I need a reproducible testcase, otherwise I do not know where to look. As a start, could you please attach your formatter settings? These two files from the userdir should be enough:
config/Editors/Preferences/org-netbeans-modules-editor-settings-CustomPreferences.xml
config/Editors/text/x-java/Preferences/org-netbeans-modules-editor-settings-CustomPreferences.xml

Thanks.
Comment 5 _ gtzabari 2011-11-04 14:45:19 UTC
Created attachment 112842 [details]
Testcase

It doesn't seem to be formatting related. The userdir paths you mentioned don't exist for me. Specifically, config/Editor is missing.

Take a look at the attached testcase. Open up App.java, apply the refactoring to the inner class and you should get a malformed result.

PS: I believe this bug is specific to the October 31st build. When I tried an older build from October 5th I couldn't reproduce the problem.
Comment 6 Jan Lahoda 2011-11-07 10:14:51 UTC
Thanks. The problem appears to be in line endings: internally, the NB infrastructure uses solely '\n' newlines, but the '\r\n'->'\n' conversion is missing on one place, leading to this problem. I am working on a fix.
Comment 7 Jan Lahoda 2011-11-07 12:03:35 UTC
Fixed:
http://hg.netbeans.org/jet-main/rev/07f201c630f8

Gili, Jirka, please verify (mainly on Windows). Thanks.
Comment 8 Quality Engineering 2011-11-08 15:39:22 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/07f201c630f8
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #204638: need to use '\n' lineendings when diffing newly created files.
Comment 9 Jiri Prox 2011-12-07 14:43:09 UTC
The formatting seems to be fine, but there is problem the comments are doubled -> filed as separated issue 206086