You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/04 21:53:26 UTC

[GitHub] [beam] damccorm opened a new issue, #21207: Fragile reference to private synthetic this$ field

damccorm opened a new issue, #21207:
URL: https://github.com/apache/beam/issues/21207

   The following code is using reflection to access a field with a name starting with `this$`:
   
   [https://github.com/apache/beam/blob/4fbdcca377fb9d804433f3014a7e7dfcef2e02f9/runners/spark/src/main/java/org/apache/beam/runners/spark/SparkNativePipelineVisitor.java#L186](https://github.com/apache/beam/blob/4fbdcca377fb9d804433f3014a7e7dfcef2e02f9/runners/spark/src/main/java/org/apache/beam/runners/spark/SparkNativePipelineVisitor.java#L186)
   
   The OpenJDK javac generates private synthetic fields with names starting with `this$` as an implementation detail of inner classes. In the future that implementation detail may be changing, and the `this$` field will no longer be generated for all inner classes. For more information about the proposed change, see: [https://bugs.openjdk.java.net/browse/JDK-8271717](https://bugs.openjdk.java.net/browse/JDK-8271717)
   
   Please consider alternatives to accessing the private synthetic `this$` field to ensure this code continues to work after the change. For example, consider passing an explicit copy of the enclosing instance to code that needs access to it, or adding an explicit getter to the inner class.
   
   For example, given:
   ```
   
   class Outer {
     int x;
     class Inner1 {
       int f() {
         return x;
       }
     }
     class Inner2
   {
       void g() {
         System.err.println("hello");
       }
     }
   }
   
   ```
   
   Currently `Inner1` and `Inner2` both have a synthetic field named `this$0` that stores a reference to `Outer`.
   
   In the future the implementation detail might be changing to omit the field from classes that don't reference the enclosing instance. So in the example, `Inner1` would still have the synthetic field because it accesses the field `x` in the enclosing instance `Outer`. However `Inner2` would no longer have a synthetic field, because it doesn't access any state from its enclosing instance.
   
   Imported from Jira [BEAM-13020](https://issues.apache.org/jira/browse/BEAM-13020). Original Jira may contain additional context.
   Reported by: cushon.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] damccorm commented on issue #21207: Fragile reference to private synthetic this$ field

Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on issue #21207:
URL: https://github.com/apache/beam/issues/21207#issuecomment-1547892606

   Hey, saw you added this comment several places. I'd recommend focusing on a single issue at first (I answered the underlying question here - https://github.com/apache/beam/issues/20298#issuecomment-1547888993)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lukaszspyra commented on issue #21207: Fragile reference to private synthetic this$ field

Posted by "lukaszspyra (via GitHub)" <gi...@apache.org>.
lukaszspyra commented on issue #21207:
URL: https://github.com/apache/beam/issues/21207#issuecomment-1637554886

   .take-issue


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn closed issue #21207: Fragile reference to private synthetic this$ field

Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn closed issue #21207: Fragile reference to private synthetic this$ field
URL: https://github.com/apache/beam/issues/21207


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] blazingbhavneek commented on issue #21207: Fragile reference to private synthetic this$ field

Posted by "blazingbhavneek (via GitHub)" <gi...@apache.org>.
blazingbhavneek commented on issue #21207:
URL: https://github.com/apache/beam/issues/21207#issuecomment-1546157410

   Hey there! 👋 I'm new to this repository and eager to contribute! 🌟 Could you kindly suggest some entry point or files to look into?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] lukaszspyra commented on issue #21207: Fragile reference to private synthetic this$ field

Posted by "lukaszspyra (via GitHub)" <gi...@apache.org>.
lukaszspyra commented on issue #21207:
URL: https://github.com/apache/beam/issues/21207#issuecomment-1666729707

   Hi @damccorm ,
   
   Please have a look at the proposed changes in PR #27868.
   
   Replaced the synthetic field `this$0` by explicit one, to get rid of the not recommended way of accessing instances. 
   However, the drawback of this solution is there will be always two fields generated with outer class instance (explicit and this$0). 
   If we kept using `this$0` in the code and just add getter instead, like `MapElement getOuter(){
   return MapElements.this};` we would have only one field.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org