Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 322488

Summary: [nls tooling] Hover NLS message declaration displays message from bad message bundle.
Product: [Eclipse Project] JDT Reporter: Kamil Fejfar <comediant>
Component: TextAssignee: Deepak Azad <deepakazad>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P5 CC: daniel_megert, deepakazad
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Two project where you can reproduce this bug. none

Description Kamil Fejfar CLA 2010-08-12 05:16:02 EDT
Build Identifier: M20100211-1343

If I have two (or more) message bundles with same name in different plugins it may cause problem.

Initializing works fine:

NLS.initializeMessages("cz.x.messages", AMessages.class) in plugin A
NLS.initializeMessages("cz.x.messages", BMessages.class) in plugin B

But when I hover some messge from BMessages (plugin B) and plugin A is in class path defined before plugin B, then org.eclipse.jdt.internal.corext.refactoring.nls.NLSHintHelper.getResourceBundle(IJavaProject, String, String) returns messages bundle from plugin A (it returns the first messages bundle no mather where it is defined).

Reproducible: Always

Steps to Reproduce:
Look details.
Comment 1 Dani Megert CLA 2010-08-12 05:21:10 EDT
Can you please attach a test case?
Comment 2 Kamil Fejfar CLA 2010-08-12 06:55:44 EDT
1. Create two plugins A, B.
2. In these plugins create packages with the same name (cz.x).
3. In these packages create message bundles with the same bundle name (cz.x.messages).

plugin A
--------

public class AMessages extends NLS {
	static {
		// initialize resource bundle
		NLS.initializeMessages("cz.x.messages", AMessages.class);
	}

	private AMessages() {
		
	}

	public static String a;
}

define appropriate message.properties


plugin B
--------

public class BMessages extends NLS {
	static {
		// initialize resource bundle
		NLS.initializeMessages("cz.x.messages", BMessages.class);
	}

	private BMessages() {
		
	}

	public static String b;
}

define appropriate message.properties


4. Plugin B should depend on plugin A

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="output" path="bin"/>
</classpath>


Important: classpathentry "org.eclipse.pde.core.requiredPlugins" must precede classpathentry "src"

5. Hover BMessages.b, it will return "The key is missing" because it will search b message in AMessages.
Comment 3 Kamil Fejfar CLA 2010-08-12 07:37:37 EDT
Created attachment 176454 [details]
Two project where you can reproduce this bug.

I have created two simple projects. Put these projects to your workspace, hover messageB in BMessages.java. You will get result from AMessages (bug).
Comment 4 Deepak Azad CLA 2010-08-12 08:21:34 EDT
The hover indeed shows the wrong message. I will take a look.
Comment 5 Deepak Azad CLA 2010-08-13 06:51:58 EDT
At runtime the properties files are loaded by the classloader of the Accessor class. Now each plugin has its own classloader which means that both the properties file and the Accessor class have to be in the same plugin. However for plain Java projects this is not true, the Accessor class can be one project and the properties file can be in another project - as long as the classloader is same, things will work just fine at runtime. (In short, if the projects you created were plain Java projects then the hover behavior is correct.)

In JDT we dont know if the project is a plugin project or a plain java project. Hence I do not have an easy solution in mind. (Plus the situation you describe looks kind of rare to me)
Comment 6 Deepak Azad CLA 2012-08-08 15:42:14 EDT
Based on comment 5 closing as WONTFIX
Comment 7 Dani Megert CLA 2012-08-09 06:56:39 EDT
This works as expected. The Java build (& class) path order is respected and because the PDE container comes before the source, it first resolves x.message from A.