Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes in ConvertMappingCommand and GenerateEntitiesCommand... #1345

Merged

Conversation

billschaller
Copy link
Member

... when using entities with joined table inheritance

ConvertMappingCommand and GenerateEntitiesCommand both use the DisconnectedClassMetadataFactory, which allows metadata manipulation without loading the associated classes. Commit a36bea broke these two commands by adding a bailout condition in ClassMetadataFactory::populateDiscriminatorValue which checks $metadata->reflClass->isAbstract(). If the DisconnectedClassMetadataFactory is being used, $metadata->reflClass will always be null, causing a fatal error, "Fatal error: Call to a member function isAbstract() on null".

This commit adds a check to see if $metadata->reflClass is set before checking isAbstract.

… using entities with joined table inheritance

ConvertMappingCommand and GenerateEntitiesCommand both use the DisconnectedClassMetadataFactory, which allows metadata manipulation without loading the associated classes. Commit a36bea broke these two commands by adding a bailout condition in ClassMetadataFactory::populateDiscriminatorValue which checks $metadata->reflClass->isAbstract(). If the DisconnectedClassMetadataFactory is being used, $metadata->reflClass will always be null, causing a fatal error, "Fatal error: Call to a member function isAbstract() on null".

This commit adds a check to see if $metadata->reflClass is set before checking isAbstract.
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3632

We use Jira to track the state of pull requests and the versions they got
included in.

@Ocramius
Copy link
Member

@zeroedin-bill any way to get a test case for this before merge? I can work on it tomorrow otherwise

@billschaller
Copy link
Member Author

@Ocramius I don't have time till late in the week probably :/ travelling and internal bug piles...

@Ocramius
Copy link
Member

Will try dealing with it during lunch break then

@Ocramius
Copy link
Member

I could not reproduce the bug. Neither with a StaticReflectionService nor with a mock reflection service.

Will merge anyway, as the conditional doesn't hurt there.

Ocramius added a commit that referenced this pull request Mar 23, 2015
…ng-command

Fix crashes in ConvertMappingCommand and GenerateEntitiesCommand...
@Ocramius Ocramius merged commit 34168d7 into doctrine:master Mar 23, 2015
@billschaller
Copy link
Member Author

Thanks!

@billschaller billschaller deleted the fix-crash-in-convertmapping-command branch March 23, 2015 23:02
manticorp added a commit to manticorp/acl that referenced this pull request Sep 7, 2016
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities

This seems to be related to the following issue filed on the doctrine github:

doctrine/orm#4459

and the following pull request:

doctrine/orm#1345

The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed:

From:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if ($metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

To:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
manticorp added a commit to manticorp/acl that referenced this pull request Sep 7, 2016
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities

This seems to be related to the following issue filed on the doctrine github:

doctrine/orm#4459

and the following pull request:

doctrine/orm#1345

The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed:

From:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if ($metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

To:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
patrickbrouwers pushed a commit to laravel-doctrine/acl that referenced this pull request Sep 27, 2016
Fixes [BUG] Call to member function isAbstract on null in mappedEventSubscriber doctrine:generate:entities

This seems to be related to the following issue filed on the doctrine github:

doctrine/orm#4459

and the following pull request:

doctrine/orm#1345

The generate:entities command uses the ```DisconnectedClassMetadataFactory``` and so ```getReflectionClass``` isn't guaranteed to return anything and can be null, as such the following lines in ```LaravelDoctrine\ACL\Mappings\Subscribers\MappedEventSubscriber``` should be changed:

From:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if ($metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

To:

```
    /**
     * A MappedSuperClass or Abstract class cannot be instantiated.
     *
     * @param ClassMetadata $metadata
     *
     * @return bool
     */
    protected function isInstantiable(ClassMetadata $metadata)
    {
        if ($metadata->isMappedSuperclass) {
            return false;
        }

        if (!$metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) {
            return false;
        }

        return true;
    }
```

I've tried it and it seems to work fine after that - but I don't know if this will affect anything else internally.
@lcobucci lcobucci added this to the 2.6.0 milestone Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants