brooklyncentral / brooklyn

This project has moved and is now part of the ASF
https://github.com/apache/incubator-brooklyn
72 stars 27 forks source link

BUG: Brooklyn Entities can't be used with a normal javac #406

Closed pveentjer closed 11 years ago

pveentjer commented 11 years ago

When I use a normal javac to compile a completely ordinary entity, I get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project brooklyn-social-apps: Compilation failure [ERROR] /Users/alarmnummer/Java/Projects/Cloudsoft/brooklyn-social-apps/src/main/java/io/cloudsoft/socialapps/drupal/Drupal.java:[15,8] brooklyn.entity.rebind.Rebindable cannot be inherited with different arguments: <> and

When I enable the groovy compiler in the pom.xml, the error is gone.

The entity:

public class Drupal extends SoftwareProcessEntity {

... here were a lot of config keys

public Drupal(Map flags) {
    this(flags, null);
}

public Drupal(Entity owner) {
    this(new LinkedHashMap(), owner);
}

public Drupal(Map flags, Entity owner) {
    super(flags, owner);
}

@Override
public Class getDriverInterface() {
    return DrupalDriver.class;
}

@Override
protected void connectSensors() {
    super.connectSensors();
    FunctionSensorAdapter serviceUpAdapter = sensorRegistry.register(new ServiceUpSensorAdapter());
    serviceUpAdapter.poll(SERVICE_UP);
}

private class ServiceUpSensorAdapter extends FunctionSensorAdapter {

    public ServiceUpSensorAdapter() {
        //we want to scan every 10 seconds.
        super(MutableMap.of("period", new TimeDuration(0, 0, 10, 0)));
    }

    @Override
    public Object call() {
        return getDriver().isRunning();
    }
}
}
ahgittin commented 11 years ago

i'm not encountering this. i've removed all the eclipse + groovy references in the pom and it compiles fine for me. see:

https://github.com/ahgittin/brooklyn-social-apps/compare/fix;pom-tidy

what version of java are you running? i'm on 1.6.0_37. there is a fix somewhere between 1.6.0_16 and 1.6.0_23 which fixes some problems in this area, according to:

http://stackoverflow.com/questions/4829576/javac-error-inconvertible-types-with-generics
pveentjer commented 11 years ago

Hi Alex,

I'm running:

PVeentjer-3:base alarmnummer$ java -version java version "1.7.0_09" Java(TM) SE Runtime Environment (build 1.7.0_09-b05) Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

pveentjer commented 11 years ago

When I switch to:

PVeentjer-3:brooklyn-social-apps alarmnummer$ java -version java version "1.6.0_29" Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3909) Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode) PVeentjer-3:brooklyn-social-apps alarmnummer$

The problem is not happening. So perhaps the bug is not solved in 1.7?

pveentjer commented 11 years ago

And switching back to 1.7 gives the initial compilation error.

pveentjer commented 11 years ago

I just had a quick peek at the places that actually implement and parametrize Rebindable. For entities, it only happens on Entity. There is no deep hierarchy of type parameter passing. So I really don't understand why the javac would complain about this extremely basic usage of generics.

ahgittin commented 11 years ago

I suspect the groovy compiler is doing something funny at AbstractEntity.

I wonder if inserting a new (java) interface RebindableEntity extends Rebindable in the hierarchy would help.

Best, Alex On Nov 29, 2012 11:40 AM, "Peter Veentjer" notifications@github.com wrote:

I just had a quick peek at the places that actually implement and parametrize Rebindable. For entities, it only happens on Entity. There is no deep hierarchy of type parameter passing. So I really don't understand why the javac would complain about this extremely basic usage of generics.

— Reply to this email directly or view it on GitHubhttps://github.com/brooklyncentral/brooklyn/issues/406#issuecomment-10862913.

pveentjer commented 11 years ago

Just tried it:

 public class Drupal extends SoftwareProcessEntity implements Rebindable<EntityMemento> {

That doesn't solve the problem.

I also tried to cheat my way out relying on a covariant return type instead of generics:

 public interface Entity extends Serializable, Rebindable{

      RebindSupport<EntityMemento> getRebindSupport();
 }

But that also didn't solve the problem..

I'm going to compile the API module without the groovy compiler in place and see what happens.

pveentjer commented 11 years ago

Also tried building the API module with javac and core/base with groovy. Also didn't solve the problem.

pveentjer commented 11 years ago

Now trying to make AbstractEntity also implement Rebindable...

[edit] problem remains... nasty little creature.

pveentjer commented 11 years ago

Problem is solved. I have tried the covariant return type again and this time it apparently didn't cause problems.

So Brooklyn can now be used in a project so that: