Bug 87906 - Enum causes compiler error
Summary: Enum causes compiler error
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-14 05:10 EST by Mohan Radhakrishnan CLA
Modified: 2005-06-08 06:12 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohan Radhakrishnan CLA 2005-03-14 05:10:56 EST
The following class causes a compiler error

public enum LevelEnum{
	
	OFF( OFF_INT, "OFF" ),
	
	FATAL( FATAL_INT, "FATAL" ),
	
	ERROR( ERROR_INT, "ERROR" ),
	
	WARN( WARN_INT, "WARN" ),
	
	INFO( INFO_INT, "INFO" ),
	
	DEBUG( DEBUG_INT, "DEBUG" ),
	
	ALL( ALL_INT, "ALL" );
	
	private String levelStr;
	
	protected LevelEnum( int level, String levelStr ) {
		this.levelStr = levelStr;
	  }
	
	public String getLevelStr(){
		return levelStr;
	}
	
	public String getDescription( ) {
		switch( this ) {
			case OFF: return "OFF";
			case FATAL: return "FATAL";
			case ERROR: return "ERROR";
			case WARN: return "WARN";
			case INFO: return "INFO";
			case DEBUG: return "DEBUG";
			case ALL: return "ALL";
		    default: return "Unknown Level";
		}
	}	
}

Trace is 

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.FieldBinding.canBeSeenBy
(FieldBinding.java:140)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findField
(Scope.java:645)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding
(Scope.java:1455)
	at org.eclipse.jdt.internal.compiler.ast.FieldDeclaration.resolve
(FieldDeclaration.java:176)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve
(TypeDeclaration.java:981)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve
(TypeDeclaration.java:1063)
	at 
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve
(CompilationUnitDeclaration.java:280)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve
(Compiler.java:566)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process
(CompilationUnitProblemFinder.java:175)
	at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure
(CompilationUnit.java:142)
	at org.eclipse.jdt.internal.core.Openable.generateInfos
(Openable.java:203)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed
(JavaElement.java:547)
	at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent
(CompilationUnit.java:979)
	at 
org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation
(ReconcileWorkingCopyOperation.java:60)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:700)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation
(JavaModelOperation.java:739)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile
(CompilationUnit.java:1105)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:91)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:133)
	at 
org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile
(CompositeReconcilingStrategy.java:86)
	at 
org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile
(JavaCompositeReconcilingStrategy.java:94)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process
(MonoReconciler.java:75)
	at org.eclipse.jdt.internal.ui.text.JavaReconciler.process
(JavaReconciler.java:318)
	at 
org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run
(AbstractReconciler.java:204)
Comment 1 Mohan Radhakrishnan CLA 2005-03-14 05:19:17 EST
I removed the 'protected' modifier from the constructor because javac reported 
a problem. It seems that only 'private' is acceptable. The eclipse compiler 
error remains the same but javac compiled it.
Comment 2 Olivier Thomann CLA 2005-03-14 08:49:08 EST
Where are the *_INT constants defined? OFF_INT, FATAL_INT, ...
Comment 3 Olivier Thomann CLA 2005-03-14 08:53:28 EST
Once I defined these constants, with latest, I get:
----------
1. ERROR in C:\tests_sources\p\X.java
 (at line 23)
	protected X( int level, String levelStr ) {
	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Illegal modifier for the enum constructor; only private is permitted.
----------
1 problem (1 error)

Ok to close?
Comment 4 Philipe Mulet CLA 2005-03-14 10:27:05 EST
Looks close to bug 81724
Comment 5 Olivier Thomann CLA 2005-03-14 11:54:11 EST
Indeed, but because the line number was different I didn't want to close it as a
dup.

*** This bug has been marked as a duplicate of 81724 ***
Comment 6 Mohan Radhakrishnan CLA 2005-03-15 00:54:09 EST
I have defined the constants now. There is no static import. The other bug 
that this marked as duplicate of seems to be related to static imports.

I am using 3.1M4. Error remains the same.
Comment 7 Philipe Mulet CLA 2005-03-15 06:25:55 EST
Please reattach a complete test case for further investigation and accurately
describe what the problem is.
Comment 8 Olivier Thomann CLA 2005-03-15 21:23:40 EST
You need to use at least 3.1M5a as the dup has been fixed for M5, not M4.
Comment 9 Mohan Radhakrishnan CLA 2005-03-21 00:29:22 EST
This bug seems to be caused by static imports in 3.1M4. I checked by adding 
and removing the static imports. Whenever the static import is added I get the 
original error I reported. So it could be a duplicate.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.FieldBinding.canBeSeenBy
(FieldBinding.java:140)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findField
(Scope.java:645)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding
(Scope.java:1455)
	at org.eclipse.jdt.internal.compiler.ast.FieldDeclaration.resolve
(FieldDeclaration.java:176)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve
(TypeDeclaration.java:981)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve
(TypeDeclaration.java:1063)
	at 
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve
(CompilationUnitDeclaration.java:280)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve
(Compiler.java:566)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process
(CompilationUnitProblemFinder.java:175)
	at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure
(CompilationUnit.java:142)
	at org.eclipse.jdt.internal.core.Openable.generateInfos
(Openable.java:203)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed
(JavaElement.java:547)
	at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent
(CompilationUnit.java:979)
	at 
org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation
(ReconcileWorkingCopyOperation.java:60)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:700)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation
(JavaModelOperation.java:739)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile
(CompilationUnit.java:1105)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:91)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:133)
	at 
org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile
(CompositeReconcilingStrategy.java:86)
	at 
org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile
(JavaCompositeReconcilingStrategy.java:94)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process
(MonoReconciler.java:75)
	at org.eclipse.jdt.internal.ui.text.JavaReconciler.process
(JavaReconciler.java:318)
	at 
org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run
(AbstractReconciler.java:204)
Comment 10 Philipe Mulet CLA 2005-03-21 04:27:22 EST
So, apart from the NPE which we think is a dup, is there anything else wrong ?
If so, please reattach a complete test case for further investigation and accurately
describe what the problem is.

Once done, please reopen.
Comment 11 Frederic Fusier CLA 2005-06-08 06:12:06 EDT
Reopen
Comment 12 Frederic Fusier CLA 2005-06-08 06:12:48 EDT
The NPE does no longer happen with 3.1 RC2
=> close as WORKSFORME