Skip to content

NPE in "Externalize Strings" wizard when class already contains externalized strings #2711

@ptziegler

Description

@ptziegler

Given a Java project with org.eclipse.osgi in the classpath and the following files:

  1. Test.java
package test;

public class Test {
	String A = Messages.Test_0;
	String B = "B";
}
  1. Messages.java
package test;

import org.eclipse.osgi.util.NLS;

public class Messages extends NLS {
	private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$
	public static String Test_0;
	static {
		// initialize resource bundle
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
	}

	private Messages() {
	}
}
  1. messages.properties
Test_0=A

When opening the wizard and switching to the second page, following exception is logged, preventing me from finishing the operation:

Caused by: java.lang.NullPointerException: Cannot invoke "String.length()" because "s" is null
	at org.eclipse.jdt.internal.corext.refactoring.nls.PropertyFileDocumentModel.escape(PropertyFileDocumentModel.java:217)
	at org.eclipse.jdt.internal.corext.refactoring.nls.NLSPropertyFileModifier.addReplaceEdits(NLSPropertyFileModifier.java:186)
	at org.eclipse.jdt.internal.corext.refactoring.nls.NLSPropertyFileModifier.addChanges(NLSPropertyFileModifier.java:119)
	at org.eclipse.jdt.internal.corext.refactoring.nls.NLSPropertyFileModifier.create(NLSPropertyFileModifier.java:79)
	at org.eclipse.jdt.internal.corext.refactoring.nls.NLSRefactoring.createChange(NLSRefactoring.java:247)
	at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:119)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2505)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2533)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:90)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:123)

The problem seems to be that the wizard includes the already externalized Test_0 entry without loading its value.

Image

The value is also explicitly hidden from the viewer. So I would expect it to be ignored. Though it only disappears when changing the accessor class.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions