Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the code below: 1 import j a v a f x . s c e n e . p ai n t . C

Consider the code below:
1import j a v a f x . s c e n e . p ai n t . C ol o r ;
2// Foo i s d e si g n e d t o onl y have red b a r s . Any c o l o r t h a t has a non=z e r o red component
3// and z e r o g reen and bl u e components i s c o n si d e r e d t o be red .
4 c l a s s Foo {
5 Bar bar ;
6 p u bli c Foo (){ t h i s . bar = new Bar ( C ol o r .RED) ; }
7 p u bli c Foo ( C ol o r c ){ t h i s (new Bar ( c )) ; }
8 p u bli c Foo ( Bar b ){
9// d ouble getRed () r e t u r n s the red component o f the c o l o r i n the r an ge 0.0=1.0.
10 i f ( b . ge tV al (). getRed ()>0.0 && b . ge tV al (). getGreen ()==0.0 && b . ge tV al (). ge tBlue ()==0.0){
11// C ol o r d a r k e r () c r e a t e s a new C ol o r t h a t i s a d a r k e r v e r s i o n o f t h i s C ol o r .
12 t h i s . bar = new Bar ( b . ge tV al (). d a r k e r ()) ;
13}
14 e l s e {
15 t h i s . bar = new Bar ( C ol o r .RED) ;
16}
17}
18 p u bli c Foo ( Foo an o the r ){ t h i s . bar = an o the r . bar ; }
19 p u bli c v oid p r i n t (){ bar . p r i n t () ; }
20 p u bli c d ouble red (){ r e t u r n bar . ge tV al (). getRed () ; }
21 p u bli c Foo g e t S e l f (){ r e t u r n t h i s ; }
22 p u bli c Foo getCopy (){ r e t u r n new Foo ( t h i s ) ; }
23 p u bli c Bar [] getAsArray (){
24 Bar [] r e s = new Bar [10] ;
25 r e s [0]= bar ;
26 r e t u r n r e s ;
27}
28}
29 c l a s s Bar {
30 p r i v a t e C ol o r c ; // Assume t h a t j a v a f x . s c e n e . p ai n t . C ol o r i s immutable
31 p u bli c Bar ( C ol o r c ){ t h i s . c = c ; }
32 p u bli c Bar ( Bar an o the r ){ t h i s . c = an o the r . ge tV al () ; }
33 p u bli c C ol o r ge tV al (){ r e t u r n t h i s . c ; }
34 p u bli c v oid s e tV al ( C ol o r c ){ t h i s . c = c ; }
35 p u bli c v oid p r i n t (){ System . out . p r i n t l n ( c ) ; }
36}
There might be one or several instances of representation exposure here. Write a minimal code snippet that reveals the most
dangerous representation exposure. Explain why it is dangerous. Note that you need to write code that exploits this dangerous
representation exposure. Just pointing out lines of the provided code that allow this exposure is not sufficient. Make sure to avoid
false positives (i.e., classifying something as a dangerous representation exposure whereas it is not a representation exposure at all
or it is but not dangerous).
If there is no representation exposure, write None in the provided code. and then propose a change in the provided code that would
exemplify an instance of a dangerous representation exposure.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago