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.
Created attachment 149823 [details] Java application source needed to reproduce the problem Summary ======= Using a lambda expression to instantiate an Iterable instance can generate an invalid class file, causing a "ClassFormatError: Duplicate field name&signature". Steps To Reproduce ================== [1] Create a simple Java application in NetBeans using the attached file CreateBadClassFile.java. It creates a collection of three Widget objects, then iterates over them, displaying their content to the console. The iteration is done twice, first by calling "forEach()", and then using a "for each" loop. [2] Run the application to verify that it works. It should generate the following console output: .foreach() call: W1 W2 W3 for each loop: W1 W2 W3 [3] To provoke the ClassFormatError, rename the unused local variable "Widget harmless" to "Widget hasNext" within the lambda expression assigned to myIterator1, where "hasNext" is also the name of a local method. Run the application again to get the error. Renaming to the other local method name ("next") also provokes the problem. Note that the variable type must also be "Widget" to cause the problem. For example, "Widget next = null;" causes the ClassFormatError, but "String next = null;" does not. [4] After generating the ClassFormatError by declaring "Widget hasNext", look at the class file that failed to load using "javap.exe -p WidgetCollection$1.class". There is no hasNext() method, but two local variables named hasNext, one of type Widget, and one of type Object: Compiled from "CreateBadClassFile.java" class createbadclassfile.WidgetCollection$1 implements java.util.Iterator<Widget> { private Widget hasNext; private int index; private java.lang.Object hasNext; final createbadclassfile.WidgetCollection this$0; createbadclassfile.WidgetCollection$1(createbadclassfile.WidgetCollection); public Widget next(); } That presumably explains the runtime error message "ClassFormatError: Duplicate field name&signature". [5] Now change method WidgetCollection.iterator() to return "myIterator2.iterator()", so that the Iterable instance is instantiated from an anonymous class rather than a lambda expression. It always runs fine, even if a local variable name is the same as a method name, so the problem appears to be confined to generating a class file from a lambda expression. Environment =========== Product Version: NetBeans IDE 8.0.1 (Build 201408251540) Java: 1.8.0_20; Java HotSpot(TM) 64-Bit Server VM 25.20-b23 Runtime: Java(TM) SE Runtime Environment 1.8.0_20-b26 System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb) User directory: C:\Users\JohnDoe\AppData\Roaming\NetBeans\8.0.1 Cache directory: C:\Users\JohnDoe\AppData\Local\NetBeans\Cache\8.0.1
reproducible but I can reproduce it even from command line -> looks like bug in JDK
skomisa, please file with all the details at http://bugreport.java.com/