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.
It would be nice if whenever in a New Project wizard you were asked to select an existing Java package root, the wizard would do a quick check for representative Java sources and verify that the package names inside each really correspond to their location within the package root. If not, the wizard should show a warning message (and possibly disable the Next/Finish button, though there may be exceptional cases where this would be very annoying). Could be a static utility method somewhere in java/project, perhaps? Or even in java/api since it is not exactly project-specific. Could possibly have one method to find the Java package name for a given FileObject - returning a String package name (possibly "") if it could be parsed correctly, or null if the file was malformed somehow - used also by DefaultClassPathProvider; and a utility method to verify a package root, by looking for some **/*.java and checking the package names against the relative paths.
May be too late for D. Should be considered a priority for E, however.
An additional possible utility method would be to take a folder and scan for likely package roots inside of it. However I am not sure any of our existing wizards would use such a method. Package root verification would apply to j2seproject import; freeform project creation and customization; possibly to web app import, TBD.
*** Issue 61234 has been marked as a duplicate of this issue. ***
Please, reevaluate. Will this be done for F?
Easy to do, it can be done to 4.2 as a fix
Something like this: String WHITESPACE = "(?:\\s|/\\*(?:[^*]|\\*[^/])*\\*/)"; String IDENTIFIER = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; String QUALIFIED_IDENTIFIER = "(?:" + IDENTIFIER + "(?:\\." + IDENTIFIER + ")*)"; Pattern PACKAGE = Pattern.compile( "^" + WHITESPACE + "*(?:package" + WHITESPACE + "+(" + QUALIFIED_IDENTIFIER + ")|(?:import|public|final|abstract|strictfp|class|interface|enum))", Pattern.DOTALL); FileObject findRoot(FileObject file) { if (file.isFolder()) { // could also scan for contained files here return null; } // look for package statement try { InputStream is = file.getInputStream(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream((int) file.getSize()); FileUtil.copy(is, baos); String content = baos.toString(); // XXX default encoding OK? Matcher m = PACKAGE.matcher(content); if (m.find()) { String pkg = m.group(1); FileObject root = file.getParent(); List<String> components = new ArrayList<String>(); if (pkg != null) { StringTokenizer tok = new StringTokenizer(pkg, "."); while (tok.hasMoreTokens()) { components.add(tok.nextToken()); } Collections.reverse(components); } for (String component : components) { if (root == null || !root.getNameExt().equals(component)) { return null; } root = root.getParent(); } return root; } } finally { is.close(); } } catch (IOException x) { Exceptions.printStackTrace(x); } return null; }