[Java 5.0 - "for"] Bug or not stupid developer? ;)

Hi,

I get a really annoying compiler error when trying to compile one of my classes. The trigger is the usage of the new for-loob, introduced in 5.0.
I don't know if it is a compiler bug or if the developer is a little tired tonight ;)




The compiler says:
-


Error: line (65) incompatible types

found : java.lang.Object

required: de.xore.versioning.persistence.internal.ReferenceRepresentation
-



Line 65 of the concerned class file looks like this:

-


63: ObjectRepresentation actualRepresentation = persistentClassHolder.getActualVersion();
65: for ( ReferenceRepresentation referenceRepresentation : actualRepresentation.getReferenceRepresentations() ) {
-



ObjectRepresentation:
-


private List referenceRepresentations = new ArrayList(); public List]]> getReferenceRepresentations() {
return Collections.unmodifiableList( referenceRepresentations );
}
-



The for-loop works nice in the other locations (even with exactly the same class and method).
Idea does not show any errors...


Any ideas?


5 comments

Hello, Johannes,
is the problem reproducible if you compile ObjectRepresentation first, then
for loop code, I mean with ctrl-shift-f9?

Eugene.

"Johannes Schneider" <idea@johannes-schneider.info> wrote in message
news:7704637.1103225555118.JavaMail.itn@is.intellij.net...

Hi,

>

I get a really annoying compiler error when trying to compile one of my

classes. The trigger is the usage of the new for-loob, introduced in 5.0.

I don't know if it is a compiler bug or if the developer is a little tired

tonight ;)
>
>
>
>

The compiler says:
-----------
Error: line (65) incompatible types

>

found : java.lang.Object

>

required: de.xore.versioning.persistence.internal.ReferenceRepresentation
-----------

>

Line 65 of the concerned class file looks like this:

>

-----------
63: ObjectRepresentation actualRepresentation =

persistentClassHolder.getActualVersion();

65: for ( ReferenceRepresentation referenceRepresentation :

actualRepresentation.getReferenceRepresentations() ) {

------------

>

ObjectRepresentation:
------------
private List<ReferenceRepresentation> referenceRepresentations = new

ArrayList(); >]]>

public List<ReferenceRepresentation> getReferenceRepresentations() {
return Collections.unmodifiableList( referenceRepresentations );
}
------------

>

The for-loop works nice in the other locations (even with exactly the same

class and method).

Idea does not show any errors...

>
>

Any ideas?

>
>
>


0

Additional info:

Iterator]]> iter = objectRepresentation.getReferenceRepresentations().iterator();
while ( iter.hasNext() ) {
ReferenceRepresentation referenceRepresentation = iter.next();


works as expected.

0

Yes - the same compiler error occurs ever time.

Tried the following (and much more):

- shutting down idea
- Deleting compiler output manually
- build project

- rebuild project

- Compiling (ctrl-shift-f9) ObjectRepresentation
- Compiling PersistenceManager

...

Always the same annoying error...

0

Here are the affected classes:

PersistenceManager (where the compiler error occurs):

package de.xore.versioning.persistence;

import de.xore.versioning.VersionInformation;
import de.xore.versioning.clone.CloneException;
import de.xore.versioning.configuration.CascadingNorm;
import de.xore.versioning.configuration.ConfigurationException;
import de.xore.versioning.configuration.ReferenceConfiguration;
import de.xore.versioning.persistence.internal.ObjectRepresentation;
import de.xore.versioning.persistence.internal.ReferenceRepresentation;
import de.xore.versioning.persistence.internal.RepresentationFactory;
import de.xore.versioning.utils.ReflectionHelper;

import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;

/*

  • Created by XoreSystems (Johannes Schneider)

  • User: johannes

  • Date: 17.12.2004

  • Time: 17:43:09

*
*/

/**

  • <p/>

  • Date: 17.12.2004<br> Time: 17:43:09<br>

*

  • Systems</a>

*/
public class PersistenceManager {
private static PersistenceManager instance = new PersistenceManager();

public static PersistenceManager renewInstance() {
instance = new PersistenceManager();
return instance;
}

public static PersistenceManager getInstance() {
return instance;
}

private PersistentObjectContainerManager persistentObjectContainerManager = new PersistentObjectContainerManager();

private PersistenceManager() {
}

public void delete( Object persistentObject ) {
persistentObjectContainerManager.delete( persistentObject );
}

public PersistentObjectContainer getPersistentClassContainer( String id ) {
return persistentObjectContainerManager.getPersistentClassContainer( id );
}

public Object loadObject( String id ) throws CloneException, NoSuchMethodException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, InstantiationException, ClassNotFoundException {
PersistentObjectContainer persistentObjectHolder = persistentObjectContainerManager.getPersistentClassContainer( id );
if ( persistentObjectHolder == null ) {
throw new IllegalArgumentException( "Kein Objekt mit der ID " + id + " gefunden" );
}

ObjectRepresentation actualRepresentation = persistentObjectHolder.getActualVersion();
return loadObject( actualRepresentation );

}

/**

  • Lädt anhand einer ObjectRepresentation ein Object

*/
private Object loadObject( ObjectRepresentation objectRepresentation ) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
Object loaded = objectRepresentation.createObjectWithOnlyPrimitives();

/*
for ( ReferenceRepresentation referenceRepresentation : objectRepresentation.getReferenceRepresentations() ) {
*/
Iterator]]> iter = objectRepresentation.getReferenceRepresentations().iterator();
while ( iter.hasNext() ) {
ReferenceRepresentation referenceRepresentation = iter.next();

String referenceName = referenceRepresentation.getName();
Object referenceValue = loadObject( referenceRepresentation.getVersionInformation() );
ReflectionHelper.setAttribute( loaded, referenceName, referenceValue );
}

return loaded;
}

/**

  • Lädt ein Objekt anhand seiner VersionInformation

*/
private Object loadObject( VersionInformation versionInformation ) throws NoSuchMethodException, IllegalAccessException, NoSuchFieldException, InvocationTargetException, InstantiationException, ClassNotFoundException {
ObjectRepresentation objectRepresentation = getPersistentClassContainer( versionInformation.getId() ).getVersion( versionInformation );
return loadObject( objectRepresentation );
}

/**

  • Speichern. Aber bitte alle Objekte einzeln - damit sie auch unabhängig vom Vater-Objekt gefunden werden können.

  • todo Jedes Objekt wird automatisch als neue Version gespeichert -

  • <p/>

  • todo Zykel müssen erkannt werden

*/
public VersionInformation save( Object toBeSaved ) throws PersistenceException, ConfigurationException, IllegalAccessException, NoSuchFieldException {
PersistentObjectContainer persistentObjectContainer = persistentObjectContainerManager.getOrCreatePersistentClassContainer( toBeSaved );

//Die Kinder nicht vergessen - Rekursion mit nachgestelltem Speichern
RepresentationFactory representationFactory = new RepresentationFactory( toBeSaved );

/*
for ( ReferenceConfiguration referenceConfiguration : representationFactory.getReferenceConfigurations() ) {
*/
Iterator]]> iterator = representationFactory.getReferenceConfigurations().iterator();
while ( iterator.hasNext() ) {
ReferenceConfiguration referenceConfiguration = iterator.next();

//Das Kind speichern + hinzufügen zu Factory
if ( referenceConfiguration.getCascadingNorm() == CascadingNorm.FALSE ) continue;
Object value = ReflectionHelper.getAttributeValue( toBeSaved, referenceConfiguration.getName() );
VersionInformation versionInformation = save( value );

representationFactory.setVersionInformation( versionInformation, referenceConfiguration );
}

ObjectRepresentation objectRepresentation = representationFactory.create();
return persistentObjectContainer.save( objectRepresentation );
}

public PersistentObjectContainerManager getPersistentClassContainerManager() {
return persistentObjectContainerManager;
}
}

0

And the ObjectRepresentation:

package de.xore.versioning.persistence.internal;

import de.xore.versioning.utils.ReflectionHelper;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*

  • Created by XoreSystems (Johannes Schneider)

  • User: johannes

  • Date: 14.12.2004

  • Time: 21:56:01

*
*/

/**

  • Repräsentiert ein persistentes Objekt. Aus dieser "Bauanleitung" kann wieder eine Instanz des urpsrünglichen Objekts

  • erstellt werden.

  • <p/>

  • Diese Bauanleitung könnte auch sehr einfach in eine Datenbank gespeichert werden.

  • <p/>

  • Date: 14.12.2004<br> Time: 21:56:01<br>

*

  • Systems</a>

*/
public class ObjectRepresentation { private String id; private List primitiveRepresentations = new ArrayList(); private List referenceRepresentations = new ArrayList(); private String typeName; public ObjectRepresentation( String typeName ) { this.typeName = typeName; } public void addPrimitiveRepresentation( PrimitiveRepresentation primitiveRepresentation ) { primitiveRepresentations.add( primitiveRepresentation ); } public void addReferenceRepresentation( ReferenceRepresentation referenceRepresentation ) { referenceRepresentations.add( referenceRepresentation ); } public T createObjectWithOnlyPrimitives() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { return new ObjectCreator().create(); } public List getReferenceRepresentations() { return Collections.unmodifiableList( referenceRepresentations ); } public List getPrimitiveRepresentations() { return Collections.unmodifiableList( primitiveRepresentations ); } public String getId() { return id; } public void setId( String id ) { this.id = id; } private class ObjectCreator ]]> {
private T create() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchFieldException {
Object createdObject = ReflectionHelper.createInstance( typeName );
ReflectionHelper.setId( createdObject, id );

setPrimitives( createdObject );
return ( T ) createdObject;
}

private void setPrimitives( Object createdObject ) throws IllegalAccessException, NoSuchFieldException {
for ( PrimitiveRepresentation representation : primitiveRepresentations ) {
ReflectionHelper.setAttribute( createdObject, representation.getName(), representation.getValue() );
}
}
}
}

0

Please sign in to leave a comment.